The pattern-recognition checklist
You now own ten patterns. Interview problems rarely announce which one they want, but they leak it through trigger phrases. This table is the course in one screen. Read the cue, name the pattern, recall the lesson:
| The problem says... | Reach for | Built in |
|---|---|---|
| sorted input, or O(log n) required | binary search | 2-2 |
| smallest/largest X that passes a monotonic test | binary search on the answer | 2-3 |
| pairs/order in an array, no better idea yet | sort-then-solve | 3-3 |
| pair in sorted data, palindrome, converging ends | two pointers | 4-1 |
| best contiguous run/substring/subarray | sliding window | 4-2 |
| repeated range totals, count subarrays summing to k | prefix sums | 4-3 |
| all subsets / permutations / boards | backtracking | 6-1, 6-2 |
| fewest steps, all steps equal cost | BFS | 7-2 |
| explore/count regions, connectivity | DFS | 7-1, 7-2 |
| fastest route with weights ≥ 0 | Dijkstra | 10-2 |
| prerequisites, must-come-before | topological sort | 10-3 |
| max/min/count over choices that interact | DP | 9-1 → 10-1 |
| "seen before?", counting, complements | hash set/dict | 1-1 |
Greedy (unit 8) is the special case: propose it, hunt a counterexample, and only trust it with an exchange argument.
Quiz
"Given a maze, find the minimum number of moves from the entrance to the exit." Which pattern?
Quiz
"Find the smallest shipping capacity that delivers all packages within d days." Which pattern?
Code exercise · python
Capstone exercise: merge overlapping intervals, an interview staple that composes sort-then-solve (3-3) with neighbor merging. Sort, seed merged with the first interval, then either extend merged[-1] or append.
Problem
"Print every possible team of 3 people chosen from a list of 10." Which pattern from the checklist?