Coding interview patterns — the 150-problem plan
The 14 patterns behind most coding interview questions, the order to learn them, and a 6-week plan to finish 150 problems.
Why patterns, not random problems
Most interview questions are the same 14 ideas in new clothes. If you learn the idea once and practise 8–12 problems on it, you can solve new ones you have never seen. Solving 500 random problems without patterns is slower and you forget them.
The 14 patterns (learn in this order)
Definition: A hash table is a data structure that stores key–value pairs and uses a hash function to compute an index into an array of buckets, giving average O(1) insert, lookup and delete.
How it works: The hash function maps a key to a bucket; collisions (two keys in one bucket) are handled by chaining or open addressing. Performance degrades to O(n) in the worst case, so good hash functions and resizing matter.
Example: Python dict, Java HashMap: checking "[email protected]" in seen is instant.
Definition: Dynamic programming solves a problem by breaking it into overlapping subproblems, solving each subproblem once and storing its result.
How it works: It applies when a problem has optimal substructure and overlapping subproblems. Memoisation = top-down recursion with a cache; tabulation = bottom-up filling of a table. Define the state, the transition (recurrence) and the base cases.
Example: Ways to climb n stairs = ways(n−1) + ways(n−2), computed once per n.
🧒 In simple words
| # | Pattern | When to think of it | Starter problem |
|---|---|---|---|
| 1 | Arrays & hashing | "find duplicates", "count", "pairs that sum to" | Two Sum |
| 2 | Two pointers | sorted array, palindrome, pairs from both ends | Valid Palindrome |
| 3 | Sliding window | "longest / shortest substring or subarray with…" | Longest substring without repeating characters |
| 4 | Stack | brackets, "next greater element", undo | Valid Parentheses |
| 5 | Binary search | sorted data, "minimum value that works" | Search in rotated sorted array |
| 6 | Linked list | reverse, merge, cycle | Reverse Linked List |
| 7 | Trees (DFS/BFS) | anything with a root and children | Maximum depth of binary tree |
| 8 | Heap / priority queue | "top K", "K closest", merge K lists | Kth largest element |
| 9 | Backtracking | "all combinations / permutations / subsets" | Subsets |
| 10 | Graphs | grids, islands, prerequisites | Number of islands |
| 11 | Dynamic programming 1-D | "number of ways", "max profit", choices in a line | Climbing stairs |
| 12 | Dynamic programming 2-D | two strings, grids | Longest common subsequence |
| 13 | Greedy & intervals | meetings, merging ranges | Merge intervals |
| 14 | Bit manipulation & maths | XOR tricks, powers of two | Single number |
How to practise one problem (the 25-minute rule)
- Read the problem twice. Write 2 small examples by hand.
- Say the brute-force idea out loud, with its time complexity.
- Ask: which pattern does this look like? Improve the idea.
- Code it. Run your examples. Then try an empty input and a single element.
- Stuck for 25 minutes? Read the solution, close it, and write it again yourself tomorrow.
Keep a "mistakes notebook": one line per problem — what the trick was. Re-read it every Sunday.
6-week plan (about 25 problems a week)
| Week | Patterns | Target |
|---|---|---|
| 1 | Arrays & hashing, two pointers | 25 easy/medium |
| 2 | Sliding window, stack, binary search | 25 |
| 3 | Linked list, trees | 25 |
| 4 | Heap, backtracking, graphs | 25 |
| 5 | Dynamic programming | 25 |
| 6 | Greedy, intervals, bits + 10 mixed mocks | 25 |
Big-O in one table
Definition: Big-O notation describes an upper bound on how an algorithm's running time or memory grows as the input size n grows, ignoring constants and lower-order terms.
How it works: We usually quote the worst case. O(1) constant, O(log n) logarithmic, O(n) linear, O(n log n) linearithmic, O(n²) quadratic, O(2ⁿ) exponential. Space complexity uses the same notation for memory.
Example: Scanning a list once is O(n); two nested loops over it are O(n²).
🧒 In simple words
| Complexity | Means | Example |
|---|---|---|
| O(1) | instant | read arr[5] |
| O(log n) | halves every step | binary search |
| O(n) | look at each item once | find the max |
| O(n log n) | sorting | merge sort |
| O(n²) | every pair | two nested loops |
What interviewers look for
- You talk while you think — silence is the biggest mistake.
- You start with a simple working idea, then improve it.
- Clean variable names and you test your own code.
- You know the time and space complexity of your answer.
Further reading
When you finish this plan, practise on: