Crack the coding round with patterns.
Fifteen patterns cover most interview problems. Learn the signals, memorise a template, and spend the interview on the twist.
Six steps, every round
Clarify
Restate the problem. Ask about input size, duplicates, negatives, empty input, and what to return.
2 minExamples
Work one normal and one edge example by hand. It catches misreads before they cost you.
3 minBrute force
Say the obvious solution and its complexity. It proves you understand the problem and gives a fallback.
2 minOptimise
Match the signals to a pattern. Name the bottleneck and the data structure that removes it.
5 minCode
Write clean code with good names. Talk while you type. Leave helper details for later if needed.
15 minTest
Run your examples line by line, then edge cases. Fix bugs calmly and state the final complexity.
5 minLearn the fifteen
Two pointers
Walk inwards from both ends of a sorted sequence.
Sliding window
Grow the right edge, shrink the left edge while invalid.
Fast and slow pointers
One pointer moves twice as fast; they meet in a cycle.
Binary search
Halve the search space, including the answer space.
Prefix sums and hashing
Remember what you have seen to answer in O(1).
Monotonic stack
Keep a stack in sorted order to find the next greater or smaller.
Heap / top-K
Keep the best K so far in a size-K heap.
Intervals
Sort by start, then sweep and merge.
BFS and DFS
Explore grids and graphs; BFS gives shortest steps.
Topological sort
Order tasks so every dependency comes first.
Union-find
Merge groups and ask 'same group?' almost instantly.
Backtracking
Choose, explore, un-choose.
Dynamic programming
Define the state, write the recurrence, fill the table.
Trie
A tree of characters for fast prefix lookups.
Greedy
Take the locally best choice, and prove it is safe.
Build the components apps run on
9 low-level design problems with production-style Kotlin, a line-by-line walkthrough, edge cases, follow-ups and the iOS equivalent.
Signal to pattern
Input size → target complexity
The small things that save the round
TypeScript power tools
Map + ?? for countsmap.set(k, (map.get(k) ?? 0) + 1) is the one-line frequency map. Map keeps insertion order.Queue = array + head indexq[head++] is O(1). Array.shift() is O(n) and turns BFS quadratic.Write a 25-line MinHeapNo built-in heap: an array, sift-up, sift-down and a comparator. Flip the comparator for a max-heap.sort((a, b) => a - b)The default sort compares numbers as strings: [10, 9, 1].sort() gives [1, 10, 9].Keys by value, not referenceMap and Set compare arrays by reference. Encode cells as r * cols + c, or join into a string.Map for memoisationmemo.has(i) ? memo.get(i)! : compute. Encode multi-part states as one number or string.Infinity and -InfinityClean initial values for min and max comparisons.Explicit stacks for deep DFSJavaScript engines overflow around 10⁴ frames; use a stack for large grids.
Edge cases to test every time
Empty inputEmpty list, empty string, n = 0.One elementLoops that assume two elements break here.All the sameDuplicates break uniqueness and pointer logic.Negatives and zeroSliding windows on sums fail with negatives; use prefix sums instead.Already sorted / reversedWorst cases for naive quicksort and some greedy choices.Very large valuesNumbers are exact only up to 2⁵³ − 1; use BigInt for big products or hashes.
Bugs that cost offers
Off-by-oneDecide inclusive or exclusive bounds once and write it as a comment.path instead of [...path]Backtracking stores the same array again and again; push a copy.Visited on popMark visited when you enqueue, or BFS revisits nodes many times.Mutating while iteratingIterate over a copy or collect changes first.Missing a key in a Mapmap.get(k) is undefined, and undefined + 1 is NaN. Default with ?? 0.new Array(n).fill([])Every slot shares one array. Use Array.from({ length: n }, () => []).
How to talk through it
Narrate decisionsSay why you chose the structure, not just what you are typing.State complexity earlyBefore coding, say the target: 'n is 10⁵ so I need n log n or better'.Name things wellleft/right, seen, best: readable code is scored.Stuck? Shrink itSolve a smaller case or a simpler version aloud; interviewers often hint.Leave stubsIf time is short, write the helper signature and finish the main logic first.Own your bugsFind them by tracing an example. Calm debugging is a strong signal.