Practice Lab
Problem Solving Patterns
| Pattern | Signal | Typical Complexity | Notes |
|---|---|---|---|
| Two pointers | Sorted array, pair search, partitioning | O(n) after sorting or per fixed index | Watch pointer movement invariants and duplicate skipping. |
| Sort + fixed index + two pointers | Unique triplets, 3Sum-style pair search after choosing one value | O(n^2) | Sort, skip duplicate fixed values, then move inward based on sum. |
| Sliding window | Contiguous subarray or substring | O(n) | Track what makes a window valid. |
| Hash map counting | Frequency, lookup, deduplication | O(n) | Clarify collision and memory trade-offs if asked. |
| BFS | Shortest path in unweighted graph | O(V + E) | Use queue and visited set. |
| DFS | Traversal, components, recursion | O(V + E) | Watch recursion depth. |
| Dynamic programming | Overlapping subproblems | Varies | Define state, transition, base cases. |