Coding patterns
A coding round gives you one or two problems, and about 45 minutes. Almost none of those problems are new. They are variations on a small set of patterns. What the round really tests is whether you can spot the pattern from the problem statement, and adapt it. Then whether you can explain why it is correct, and how fast it runs. Grinding hundreds of problems teaches that slowly. Learning the patterns first, then practicing each one on purpose, teaches it fast.
This track covers the sixteen patterns that carry most of that weight. Each page explains how to recognize the pattern, and steps through it on a small input. It gives one template in five languages. And it ends with ten LeetCode problems, easy to hard, that you can tick off as you solve them.
Start with hashing and prefix sums
Watch a pattern work
Section titled “Watch a pattern work”Patterns are easier to see than to read. Every page runs its algorithm on a small input, with the pseudo-code beside it. So you can watch the state change one step at a time. Here is two pointers finding a pair that sums to 10 in a sorted array, without trying every pair. Press Step, or Play to watch it run.
- left, right = 0, len(nums) - 1
- while left < right:
- pair_total = nums[left] + nums[right]
- if pair_total == target: return [left, right]
- if pair_total < target: left += 1 # need more
- else: right -= 1 # need less
Sorted input. Start at both ends.
Which pattern?
Section titled “Which pattern?”The problem statement usually gives the pattern away. These are the phrases to listen for.
| The problem says | Try first |
|---|---|
| “Have we seen this before?”, pairs that sum to a target, counts, anagrams | Hashing |
| Subarray sums, especially with negative numbers | Prefix sums |
| A sorted array, pairs or triples, in-place rearranging, palindromes | Two pointers |
| Longest or shortest contiguous substring or subarray that meets a rule | Sliding window |
| Sorted input, or “the minimum X such that…” with a yes/no check | Binary search |
| Matching brackets, “next greater” or “previous smaller” element | Stacks |
| A tree: depth, paths, validating, level by level | Tree traversal |
| Grids, connections, fewest steps, dependencies or prerequisites | Graph search |
| The k largest, smallest, closest or most frequent; merging sorted lists | Heaps |
| “All” combinations, subsets, permutations or placements | Backtracking |
| “How many ways”, “fewest” or “most” with choices that overlap | Dynamic programming |
| Reverse, merge or reorder nodes; find a cycle or the middle | Linked lists |
| Ranges that overlap: merge, insert, rooms needed at once | Intervals |
| A 2-D grid to walk in a spiral, rotate or mark in place | Matrices |
| Count bits, the one number without a pair, add without + | Bit manipulation |
| A best choice at each step that can never hurt later | Greedy |
| Words sharing prefixes, autocomplete, many words on one board | Tries |
When two rows fit, start from the brute force and ask what work it repeats. The pattern is usually the thing that stops that repeat: a map stops a rescan, a window stops a recount, a table stops a recomputation.
Your progress
Section titled “Your progress”Tick a problem on its pattern page once you've solved it. Ticks stay in this browser; there's no account and nothing is sent anywhere.
Your path
Section titled “Your path”The patterns build on each other in this order: arrays first, then trees and graphs, then recursion. The dots show the level: ●○○ Foundation, ●●○ Mid-level, ●●● Senior. The count next to each pattern is how many of its ten problems you’ve ticked.
- See all 10
Arrays and strings
Hash maps and prefix sums, two pointers, sliding windows, binary search and stacks turn an O(n²) scan into one pass. Then linked lists, intervals, matrices, bits and greedy choices.
- 4 pages
Trees, graphs and heaps
Depth-first and breadth-first traversal, topological sort, the heap and the trie: how to walk a structure, find shortest paths, order dependencies, keep the best k items and look up prefixes.
- 2 pages
Backtracking and DP
Searching every choice with backtracking, and remembering overlapping answers with dynamic programming: the two patterns behind most hard coding questions.
- See all 75
Blind 75
The 75 classic coding interview problems, each solved from the simple way to the fast way, with a step-through, code in five languages and the Big O worked out from the code.
How to practice
Section titled “How to practice”- Try each problem for 20 to 30 minutes before you look anything up. Getting stuck and then unstuck is the part that builds recognition.
- Say the complexity out loud before you code. Interviewers ask. And saying it first often shows you the solution is too slow, before you have written it.
- Come back to a problem a week later. If you can’t solve it again from a blank editor, you learned the answer, not the pattern. Untick it, and try again.
The designbeyondcode digest, every Saturday
New deep dives, interview tips and site news in one short email. Free. Leave with one click.
We never sell or share your email. We only use it to send this newsletter.