Pattern recognition is the meta-skill that separates senior candidates from middle ones. Strong engineers rarely invent an algorithm under interview pressure — they recognize that a disguised problem is one they've seen, then apply the known technique. The work is mapping a problem statement's surface features ("shortest", "k-th", "all combinations", "contiguous subarray") to the right algorithmic family.
How recognition works
Every interview problem broadcasts cues. Train yourself to read them:
| Operation | Best | Average | Worst | Note |
|---|---|---|---|---|
| When you see… | …reach for | Why | Watch for | |
| Shortest path, unweighted | BFS | level order = distance | weighted → Dijkstra | |
| Shortest path, weighted non-negative | Dijkstra | greedy + heap | negative edge → Bellman-Ford | |
| K-th largest / top-K | heap of size K (or QuickSelect) | partial order suffices | streaming → must use heap | |
| Running median of a stream | two heaps | balance halves | — | |
| Contiguous subarray with property P | sliding window or prefix sum | avoid re-summing | negatives break window | |
| All combinations / permutations | backtracking | build + undo choices | exponential output | |
| Optimize over overlapping subproblems | dynamic programming | memoize states | no overlap → just recurse | |
| Provably-safe local choice | greedy | exchange argument | prove it or counterexample it | |
| Connectivity / grouping | union-find | near-O(1) merge & find | needs ordering → no | |
| Prefix / autocomplete matching | trie | shared prefixes | space cost | |
| Find boundary in monotonic space | binary search | halve the search | must be monotone |
The recognition checklist
Run these questions over any problem before coding:
- What's the output shape? A boolean/count → often DP or greedy. A path → graph search. All solutions → backtracking. A single optimal value → DP, greedy, or binary search on the answer.
- What's monotone? If a predicate flips once across the input or the answer range, binary search applies.
- Is there structure to exploit? Sorted → two pointers / binary search. Intervals → sort then sweep (greedy). Small set (n ≤ 20) → bitmask.
- Is the brute force exponential, and do subproblems repeat? If yes → DP. If they don't repeat → plain recursion/backtracking.
- Is it about "have I seen this?" or "how many?" → hash map.
Why this is the senior signal
Middle engineers solve problems they recognize and freeze on ones they don't. Senior engineers systematically classify an unfamiliar problem into a known family within the first two minutes, then spend the rest of the time on edge cases and complexity. The questions in this topic drill exactly that classification reflex.