Pattern recognition — reading the problem for its solution
The signals in a problem statement that name the technique before you start thinking.
Strong candidates are not faster thinkers. They have seen the shape before and recognise it in the first thirty seconds. That recognition is learnable, and this table is most of it.
| The problem says | Reach for |
|---|---|
| Sorted array, find a pair or triple | Two pointers |
| Sorted array, find a position or boundary | Binary search |
| "Minimise the maximum" / "maximum the minimum" | Binary search on the answer |
| Contiguous subarray or substring | Sliding window |
| "Seen before", "count occurrences", "duplicate" | Hash map or set |
| Range sums, repeated queries | Prefix sums |
| "k-th largest", "top k", "median of a stream" | Heap |
| Nesting, matching, "most recent unmatched" | Stack |
| "Next greater", "previous smaller", "span" | Monotonic stack |
| Fewest steps, shortest path unweighted | BFS |
| All paths, all combinations, board filling | DFS with backtracking |
| Dependencies, ordering, prerequisites | Topological sort |
| Weighted shortest path | Dijkstra |
| Connectivity, "are these joined", merging groups | Union-find |
| "Number of ways", "min/max over choices" with overlap | Dynamic programming |
| "Best choice at each step", provably safe | Greedy |
| Prefix matching, autocomplete | Trie |
| Linked list, "middle", "cycle" | Fast and slow pointers |
Read the constraints as a hint
n ≤ 20 invites exponential search. n ≤ 10⁵ rules out O(n²) and asks for O(n log n). n ≤ 10⁹ means the answer is mathematical or binary-searched, never iterated. Interviewers choose these numbers on purpose.
Two questions that unlock most problems
- What am I recomputing? Repeated work points at hashing, prefix sums, or memoisation.
- What order can I impose? Sorting frequently converts an O(n²) search into a single pass — and it costs only O(n log n) to find out.
Build the list yourself
Copying this table is useful; writing your own is better. After each problem you solve, add one line: the signal you noticed → the technique. Twenty of your own lines beat two hundred of someone else's, because you will remember the moment you wrote each one.