Goal-based paths · 15 steps
Interview preparation
The patterns that coding interviews keep returning to, in an order where each one reuses the last, with solved problems to practise every step.
- Who it is for
- Developers preparing for technical interviews who already know basic arrays, loops and Big O.
- By the end
- You can recognise the common patterns from a problem statement, explain a brute force and an improvement, and state and justify the complexity.
Step 1: Talk about complexity
Interviewers ask for the cost of every solution. These exercises cover the loop shapes that the patterns produce.
- ModuleM03 Big O· beginner
- Complexity exerciseTwo pointers moving toward each other· Θ(n)
- Complexity exerciseA while loop inside a for loop (sliding window)· Θ(n) (amortized O(1) per step)
- Complexity exerciseSort once, then binary search n times· Θ(n log n)
Step 2: Hashing
The most common first improvement over a brute force: remember what you have seen.
- PatternHashing for constant-time lookup· O(n) expected
- ProblemTwo readings that add up to a target· beginner · O(n) expected
- ProblemHas any badge been scanned twice?· beginner · O(n) expected
- ProblemSame letters, different order?· beginner · O(n) expected
Step 3: Two pointers
The O(1)-space alternative to hashing on sorted or symmetric input.
- PatternTwo pointers· O(n)
- ProblemTwo prices that fit the budget exactly· beginner · O(n)
- ProblemDoes the phrase read the same both ways?· beginner · O(n)
- ProblemTwo walls that hold the most water· intermediate · O(n)
- ProblemRed, white and blue in one pass· intermediate · O(n)
Step 4: Sliding window
Combines two pointers with a hash map for contiguous-range questions.
- PatternSliding window· O(n)
- ProblemThe busiest stretch of k hours· beginner · O(n)
- ProblemThe longest stretch without a repeated letter· intermediate · O(n) expected
Step 5: Prefix sums
Handles the range-sum questions that sliding windows cannot (negative values, counting).
- PatternPrefix sums· O(n) build, O(1) per query
- ProblemWhere do both sides weigh the same?· beginner · O(n)
- ProblemHow many stretches add up to k?· intermediate · O(n) expected
- ProblemEvery product but your own· intermediate · O(n)
Step 6: Binary search on boundaries
Boundary search shows up both on sorted arrays and on answer spaces; the invariant matters more than the code.
- PatternBinary search on a monotonic predicate· O(log R × cost of ok)
- LessonBinary search: halving a sorted range· M12 Searching
- ProblemFind the first broken build· beginner · O(log n) checks
- ProblemWhere does a value start and end?· intermediate · O(log n)
Step 7: Stacks
Matching, nesting and "next greater" questions all reduce to a stack.
- PatternMonotonic stack· O(n)
- ProblemDo the brackets close properly?· beginner · O(n)
- ProblemHow many days until it gets warmer?· intermediate · O(n)
Step 8: One-pass scans
Several classic questions need only a running best or candidate; spotting that avoids over-engineering.
- PatternOne pass with a running state· O(n)
- ProblemBuy once, sell once, profit most· beginner · O(n)
- ProblemWhich candidate has more than half the votes?· intermediate · O(n)
- ProblemThe best streak of daily profits· intermediate · O(n)
Step 9: Tree and graph traversal
BFS and DFS are expected knowledge; the visualizer makes both orders concrete.
- PatternBreadth-first search and level order· O(V + E)
- PatternDepth-first search and backtracking· O(V + E) for graph DFS; O(2ⁿ) subsets, O(n!) permutations
- VisualizerTree traversal· Θ(n)
- ModuleM24 BFS and DFS· intermediate
Step 10: Heaps
Top-K and merging sorted streams are standard follow-up questions.
- PatternTop K with a heap· O(n log k)
- ModuleM21 Heaps and Priority Queues· intermediate
Step 11: Intervals and greedy choices
Scheduling questions test whether you can justify a greedy rule rather than guess it.
- PatternSort and merge intervals· O(n log n)
- PatternGreedy choice after sorting· O(n log n)
Step 12: Dynamic programming
Start with one-dimensional states; most interview DP problems are variations on these.
- PatternDynamic programming (1D and 2D)· O(states × transitions)
- ProblemHow many ways up the stairs?· beginner · O(n)
- ProblemCollect the most without taking neighbours· intermediate · O(n)
Step 13: Dependencies and connectivity
Course schedules and connected groups are the usual graph questions beyond plain traversal.
- PatternTopological ordering· O(V + E)
- PatternUnion-find for connectivity· O(α(n)) amortized per operation
Step 14: Bit tricks
Short questions that check you know XOR and masks; cheap to learn, common as warm-ups.
- PatternBit tricks and arithmetic invariants· O(n) scans; O(set bits) popcount; O(log min(a, b)) gcd
- ProblemThe sock without a pair· beginner · O(n)
- ProblemThe one ticket that never came back· beginner · O(n)
Step 15: Combine and review
The final module practises reading constraints to choose a pattern, which is the real interview skill.