Interview sequences
Curated orders for working through the patterns and solved problems before a coding interview. They suggest a pace; they do not time you, score you or judge your code. The goal is to recognise a pattern, explain an approach and justify its cost, which no timer can measure.
A routine for every problem
- Read the statement and restate it in your own words, including the input limits.
- Describe a brute force and its cost before improving it. Interviewers want to hear both.
- Name the pattern you think applies and the signal that suggested it; open the pattern page if you are unsure.
- Reveal hints one at a time only when stuck, then write the solution in the language you will interview in.
- Test the edge cases from the problem page by hand: empty input, one element, duplicates, extremes.
- State time and extra space, and say why. Then compare with the written solution and its correctness argument.
- Explain the solution out loud as if to an interviewer. If the explanation stalls, that is the part to revisit.
2 weeks · 10 sessions
Two-week refresher
For developers who learned these topics before and need them fresh: the most common array, hashing, stack, search and DP patterns, one focused session at a time.
Ten sessions, roughly one per working day. Skip what you can already explain; repeat what you cannot.
Week 1: arrays, hashing and pointers
Get fluent at turning a nested-loop idea into a single pass, and at stating why it is correct.
Session 1Hashing for lookup
Say the brute force out loud first, then remove its inner loop with a map or set.
- 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
Session 2Two pointers
For each pointer move, say which candidates it rules out and why none of them was the answer.
- 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)
- ProblemPush the empty slots to the end· beginner · O(n)
Session 3Harder pointer moves
Partitioning and the container problem need a sharper argument for which side to move.
- ProblemTwo walls that hold the most water· intermediate · O(n)
- ProblemRed, white and blue in one pass· intermediate · O(n)
- ProblemKeep one copy of each sorted value· beginner · O(n)
Session 4Sliding window
Name the window invariant, then decide when to record the answer: after shrinking (longest) or while shrinking (shortest).
- PatternSliding window· O(n)
- ProblemThe busiest stretch of k hours· beginner · O(n)
- ProblemThe longest stretch without a repeated letter· intermediate · O(n) expected
Session 5Prefix sums
Explain why the window fails with negative values and how a map of prefix sums fixes it.
- 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)
Week 2: search, stacks, DP and review
Cover the remaining common shapes and practise explaining complexity without prompting.
Session 1Binary search on boundaries
Write the invariant before the loop; check the two-element case by hand.
- 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)
Session 2Stacks
Matching brackets, then the monotonic stack: say what each popped element learns.
- PatternMonotonic stack· O(n)
- ProblemDo the brackets close properly?· beginner · O(n)
- ProblemHow many days until it gets warmer?· intermediate · O(n)
Session 3One-pass scans
Identify the smallest summary of the past that still decides the current element.
- PatternOne pass with a running state· O(n)
- ProblemBuy once, sell once, profit most· beginner · O(n)
- ProblemThe best streak of daily profits· intermediate · O(n)
- ProblemWhich candidate has more than half the votes?· intermediate · O(n)
Session 4Dynamic programming
State the subproblem in one sentence, then the transition, then the base cases, then reduce the space.
- 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)
Session 5Review and traversal
Re-solve any problem from the plan you struggled with, then read the BFS and DFS patterns for follow-up questions.
- 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)
4 weeks · 17 sessions
Four-week foundation
A slower plan that rebuilds the underlying structures as well as the patterns, including trees, heaps and graphs, with time to revisit each week.
Four or five sessions a week. Each week ends with a review session; move on when you can explain the week's patterns without notes.
Week 1: cost, arrays and hashing
Be able to estimate the cost of any loop and to use a hash map as the default first improvement.
Session 1Counting cost
Work through the exercises until you can predict the growth before checking the answer.
- ModuleM03 Big O· beginner
- Complexity exerciseInner loop that depends on the outer index· Θ(n²)
- Complexity exerciseTwo pointers moving toward each other· Θ(n)
- Complexity exerciseA while loop inside a for loop (sliding window)· Θ(n) (amortized O(1) per step)
Session 2Arrays in practice
In-place updates and rotations: track exactly which indices each step touches.
- ModuleM05 Arrays· beginner
- ProblemShift the schedule by k days· intermediate · O(n)
- ProblemPush the empty slots to the end· beginner · O(n)
- ProblemMerge two sorted lists into the first one· beginner · O(m + n)
Session 3Hash maps and sets
Decide what the key is and what the value stores before writing code.
- PatternHashing for constant-time lookup· O(n) expected
- VisualizerHash table· put/get/remove expected O(1)
- 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
Session 4Week 1 review
Re-solve two problems from this week without looking, then explain their complexity aloud.
- ProblemThe one ticket that never came back· beginner · O(n)
- ProblemThe sock without a pair· beginner · O(n)
- PatternBit tricks and arithmetic invariants· O(n) scans; O(set bits) popcount; O(log min(a, b)) gcd
Week 2: pointers, windows, prefix sums and search
Recognise the four array patterns from the problem statement alone.
Session 1Two pointers
Opposite ends and read/write pointers; argue each move.
- 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)
Session 2Sliding window
Fixed then variable windows; note when the pattern does not apply.
- PatternSliding window· O(n)
- ProblemThe busiest stretch of k hours· beginner · O(n)
- ProblemThe longest stretch without a repeated letter· intermediate · O(n) expected
Session 3Prefix sums
Range sums and counting subarrays with a map.
- 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)
Session 4Binary search
Lower bound, first true of a predicate, and searching an answer space.
- PatternBinary search on a monotonic predicate· O(log R × cost of ok)
- VisualizerBinary search· O(log n)
- ProblemFind the first broken build· beginner · O(log n) checks
- ProblemWhere does a value start and end?· intermediate · O(log n)
Session 5Week 2 review
Pick three problems from weeks 1 and 2 and solve them in a different language than before.
- ProblemKeep one copy of each sorted value· beginner · O(n)
- ProblemRun-length encode a word· beginner · O(n)
- PatternOne pass with a running state· O(n)
Week 3: stacks, trees, heaps and graphs
Understand the structures interview follow-ups assume, even where this lab has no solved problem yet.
Session 1Stacks and queues
LIFO for nesting, FIFO for breadth; then the monotonic stack.
- VisualizerStack· push/pop amortized O(1)
- VisualizerQueue (ring buffer)· enqueue/dequeue O(1)
- PatternMonotonic stack· O(n)
- ProblemDo the brackets close properly?· beginner · O(n)
- ProblemHow many days until it gets warmer?· intermediate · O(n)
Session 2Tree traversal
Step through all four traversal orders and say which data structure drives each.
- ModuleM18 Trees· intermediate
- VisualizerTree traversal· Θ(n)
- 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
Session 3Heaps and top K
Why a min-heap of size k keeps the k largest; how your language's default heap is ordered.
- ModuleM21 Heaps and Priority Queues· intermediate
- PatternTop K with a heap· O(n log k)
Session 4Graphs
Representations, then ordering and connectivity: know when each of BFS, topological sort and union-find applies.
- ModuleM23 Graph Fundamentals· intermediate
- ModuleM24 BFS and DFS· intermediate
- PatternTopological ordering· O(V + E)
- PatternUnion-find for connectivity· O(α(n)) amortized per operation
Week 4: greedy, DP and full review
Handle optimisation questions and finish with mixed practice.
Session 1Greedy and intervals
For each greedy rule, try to break it with a three-item example before trusting it.
- PatternGreedy choice after sorting· O(n log n)
- PatternSort and merge intervals· O(n log n)
- ProblemBuy once, sell once, profit most· beginner · O(n)
Session 2Dynamic programming
Memoise the recursion first, then convert it to a table, then shrink the table.
- PatternDynamic programming (1D and 2D)· O(states × transitions)
- Complexity exerciseNaive recursive Fibonacci· Θ(φⁿ) ≈ Θ(1.618ⁿ), within O(2ⁿ)
- ProblemHow many ways up the stairs?· beginner · O(n)
- ProblemCollect the most without taking neighbours· intermediate · O(n)
- ProblemThe best streak of daily profits· intermediate · O(n)
Session 3Mixed practice
Solve problems without being told the pattern: read the constraints and name the technique first.
- ProblemWhich candidate has more than half the votes?· intermediate · O(n)
- ProblemCount the 1 bits· beginner · O(number of 1 bits) ≤ O(width)
- ProblemThe largest tile that fits both walls· beginner · O(log min(a, b)) iterations
Session 4Final review
Walk the pattern library and, for each pattern, say one signal that suggests it and one case where it fails.
- ModuleM35 Advanced Problem Solving· advanced
- PatternTwo pointers· O(n)
- PatternSliding window· O(n)
- PatternDynamic programming (1D and 2D)· O(states × transitions)