Article series · 66 lessons
Algorithms & data structures
Learn to recognize a problem’s structure and explain why your solution works.
Read the series introduction →
Follow the sequence below, or pick up where you left off. Nothing is locked.
What you’ll work toward & your progress
What you’ll work toward
- Practice an algorithm without confusing recall with proof
- Choose a data structure from its contract
- Record a concrete gap and a regression test
Completion is stored on this device only. Nothing is locked; start where it makes sense.
Series preparation
Explicitly listed by the series introduction; lesson order does not create a prerequisite.
Before the first lesson
These are the starting lesson’s prerequisites, not requirements for every advanced topic below.
How to practise this subject
For each family, state the input contract, trace a small example, produce a counterexample to a tempting shortcut, and compare your implementation with a bounded brute-force oracle.
Lessons in order
- 01
The LeetCode Game — How to Read a Problem
Read input, output and value bounds together; derive work and storage costs, then justify algorithm preconditions rather than guessing a universal time limit.
- 02
Big-O in Practice — Counting, Not Vibes
How to derive the cost of a Python data structure operation from how it is built, instead of memorising a table you half-remember under pressure.
- 03
Python for Speed — The 20 Idioms That Matter
The small set of standard-library tools that turn a fifteen-line design review solution into a five-line one, and the syntax you must be able to type without thinking.
- 04
Arrays & Strings — In-Place Discipline
Derive read/write-pointer compaction and partitioning from loop invariants, then test the boundary cases that make in-place mutation safe.
- 05
Hashing — Your Default Weapon
The complement-lookup skeleton and the general move of trading memory for time, which is the first thing to try whenever a problem looks quadratic.
- 06
UMPIRE — The Problem-Solving Framework
A six-step practice checklist for clarifying contracts, comparing approaches, planning, implementing, testing and analyzing costs—without a fixed completion-time promise.
- 07
Two Pointers I — Opposite Ends
Two indices converging from the ends of a sorted array, and the monotonicity argument that proves you can discard a whole row of candidates with one comparison.
- 08
Two Pointers II — Same Direction & Fast-Slow
Two pointers moving the same way at different speeds: the read/write compaction you already know, and Floyd's cycle detection, which finds a loop in O(1) memory.
- 09
Sliding Window I — Fixed Size
Maintaining a window aggregate incrementally so that sliding costs O(1) instead of O(k), which turns the obvious O(n*k) scan into a single pass.
- 10
Sliding Window II — Variable Size
Expand right unconditionally, shrink left while the invariant is broken, record at the right moment — and the amortisation argument that keeps it linear.
- 11
Sliding Window III — With Counts
Windows whose validity depends on a frequency map, and the single integer counter that lets you test that condition in O(1) instead of rescanning the map.
- 12
Prefix Sums & Difference Arrays
Precomputing cumulative sums to answer range queries in O(1), and the prefix-plus-hashmap combination that counts subarrays where sliding windows are unsound.
- 13
Binary Search I — The Template
One binary search template with a half-open invariant that never loops forever and never goes off by one, and the discipline of owning exactly one version of it.
- 14
Binary Search II — Rotated & 2D
Binary search when the array is no longer sorted end-to-end: decide which half is still sorted, then discard the other. Same trick flattens a 2D matrix into one index space.
- 15
Binary Search III — On the Answer
Stop searching the array and start searching the answer range: define a monotonic feasibility predicate, then binary search the smallest x for which it holds.
- 16
Stacks — LIFO & Matching
Nesting, matching, undo and expression evaluation are one idea: push what you expect, pop when it arrives, and carry auxiliary state alongside for O(1) queries like min.
- 17
Monotonic Stack
Next greater and next smaller element in O(n): keep a stack whose order never breaks, and pop everything the current element resolves.
- 18
Queues & Monotonic Deques
The queue as BFS substrate, and the monotonic deque that answers sliding-window maximum in O(n) by discarding candidates that can never win again.
- 19
Linked Lists I — Traversal & Reversal
The dummy head that deletes most linked-list edge cases, and the prev/cur/next three-step reversal you should be able to write without thinking.
- 20
Linked Lists II — Cycles, Middle, Reorder
Floyd's tortoise and hare for cycle detection and entry point, finding the middle in one pass, and composing split-reverse-merge to reorder a list in O(1) space.
- 21
Recursion & the Call Stack
Base case discipline, hand-tracing a call stack, and knowing when recursion is the wrong tool — the substrate under trees, backtracking and dynamic programming.
- 22
Trees I — DFS Traversals
Preorder, inorder and postorder as one recursive skeleton with the work line moved, plus the iterative forms and when they are worth writing.
- 23
Trees II — BFS / Level Order
Snapshot the queue length at the top of each iteration and you have level-order traversal — the one trick behind right side view, zigzag, and minimum depth.
- 24
Trees III — BST Properties
Two views of a binary search tree: inorder traversal yields sorted order, and validation requires passing bounds down rather than comparing parent to child.
- 25
Trees IV — Paths & Accumulators
The return-one-thing-track-another pattern: a recursion whose return value serves the parent while a separate accumulator records the global best.
- 26
Heaps & Top-K
When a problem asks for the K largest, K smallest, or K most frequent of anything, you almost never need to sort. A size-K heap answers it in O(n log k).
- 27
Graphs I — Representation & DFS
Build the adjacency list, carry a visited set, and recognise that a grid is already a graph — then count connected components with a depth-first sweep.
- 28
Graphs II — BFS & Shortest Path
Breadth-first search level by level, why it gives shortest paths in unweighted graphs, and the multi-source variant that solves nearest-X grid problems in one sweep.
- 29
Graphs III — Topological Sort
Kahn's in-degree algorithm for ordering tasks with dependencies, and why a queue that empties early is exactly a cycle detector.
- 30
Graphs IV — Union-Find (DSU)
Fifteen lines of disjoint-set union with path compression and union by rank, and the family of connectivity problems it collapses into near-constant time.
- 31
Backtracking I — Subsets & Combinations
One choose-explore-unchoose template that generates subsets, combinations and permutations, plus the two ways to skip duplicates without producing duplicate output.
- 32
Backtracking II — Constraint Grids
Prune partial assignments, maintain column and diagonal constraints, and restore search state in N-Queens, Word Search and Sudoku.
- 33
DP I — Recognising Overlapping Subproblems
DP is recursion plus a cache. Write the recursion, add lru_cache, convert to a table — mechanically, in that order, every time.
- 34
DP II — 1D Linear
Define dp[i] in English before you write code. The House Robber family, and why most DP bugs are undefined state rather than a wrong transition.
- 35
DP III — Take / Skip Decisions
The binary-decision DP shape: at each index you either act or you don't. State machines for cooldown, reachability for Jump Game, and split points for Word Break.
- 36
DP IV — Subsequences (LIS / LCS)
Longest Increasing Subsequence and Longest Common Subsequence are the two parent problems behind a huge family. Know both cold and most subsequence DP becomes recognition.
- 37
DP V — 0/1 Knapsack
Derive the 0/1 knapsack recurrence, prove why compressed capacity updates descend, and adapt the state to partition, sign assignments and reconstruction.
- 38
DP VI — Unbounded Knapsack
The knapsack where each item is available in unlimited supply. One character changes from 0/1 — the capacity loop direction — and Coin Change, Rod Cutting, and Combination Sum IV all fall out of it.
- 39
DP VII — 2D Grid
Grid DP is the friendliest dynamic programming: each cell is built from the one above and the one to its left. Use it to make DP feel mechanical before string DP.
- 40
DP VIII — String DP / Edit Distance
The two-string DP table: dp[i][j] over prefixes, the three-way insert/delete/replace recurrence, and how Distinct Subsequences and Interleaving String are the same table with different transitions.
- 41
DP IX — Palindromes
Expand-around-centre versus the 2D palindrome table: two O(n^2) approaches with very different failure rates, and when partitioning forces you back to explicit DP.
- 42
DP X — Interval DP
dp[i][j] over ranges with an inner split point k: why Burst Balloons only works when you think about the LAST balloon, and how sentinel padding removes the boundary cases.
- 43
DP XI — State Machine
Naming your DP states explicitly: hold and free arrays for the stock problems, why drawing the transition diagram first collapses the difficulty, and how the k-transaction version generalises.
- 44
DP XII — Bitmask DP
Encoding a subset as an integer: when n is at most 20 the exponential state is affordable, the standard submask and popcount idioms, and why the constraint tells you before the problem does.
- 45
Tries — Prefix Trees
Children dict plus terminal flag: building a trie in ten lines, and why Word Search II is trie-plus-backtracking rather than a dictionary scan.
- 46
Bit Manipulation
XOR cancels itself, n & (n-1) clears the lowest set bit, and how to add two integers without the plus operator. The handful of bit tricks that actually recur in practice.
- 47
Math & Number Theory
Fast exponentiation by squaring, the sieve of Eratosthenes, Euclid's GCD, and binary search on integers — the four math routines worth memorising outright.
- 48
Intervals
Sort by start, merge on overlap: the four-problem interval family, and why Meeting Rooms II needs a heap on top of the sort.
- 49
Greedy — And Proving It Works
Greedy feels right and is often wrong. The exchange argument, the counter-example hunt you should run first, and four problems where greedy genuinely is optimal.
- 50
Matrix Manipulation
Transpose then reverse to rotate in place, four-boundary control for spiral traversal, and using the first row and column as O(1) marker storage.
- 51
Design I — Composing for O(1)
Hashmap plus doubly-linked list for LRU, array plus index map for GetRandom, and the general move of combining two structures so each covers the other's weakness.
- 52
Design II — Streams & Time
Two balanced heaps for a running median, binary search over versioned timestamps, and merging k sorted feeds — the design patterns for data that arrives over time.
- 53
Sorting & Custom Comparators
Partition-based selection and comparator design: Dutch national flag, quickselect for Kth largest in O(n) average, and cmp_to_key for orderings that are not a simple key.
- 54
Segment Trees & Fenwick (BIT)
Range query with point update in O(log n): the recursive segment tree skeleton, the Fenwick tree's low-bit trick, and how to recognise the rare problem that actually needs one.
- 55
String Algorithms
KMP's failure function, rolling hashes, and the Z-function — the three ways to avoid re-comparing characters you have already matched.
- 56
Advanced Graphs
Dijkstra as BFS with a priority queue, Bellman-Ford for negative weights and bounded hops, and the two minimum spanning tree algorithms — with the cue for choosing between them.
- 57
Mock Set 1 — Mixed Easy/Medium, 45 min
The first cold pressure test: two unseen Easy and two unseen Medium in 45 minutes, no hints, timer visible — run as an experiment that produces data about your classifier.
- 58
Mock Set 2 — Narrated & Recorded
Two unseen Mediums with screen/audio recording and evidence-based playback review.
- 59
Blind 75 Sweep — Gap Audit
Attempt-classify all 75 problems in one structured sweep, mark each cold, warm, hint or failed, and produce the personalised weak list that drives the rest of the track.
- 60
Weak-Pattern Intensive
Take the bottom three patterns from the L59 audit and repair them with the rebuild loop: blind template, three costumes, interleaved re-test.
- 61
Mock Set 3 — One Hard, 45 min
A timed unfamiliar-hard session: investigate decompositions, state invariants, and record partial progress and assistance.
- 62
Company-Tagged — Microsoft & Amazon
Two transferable coding mocks: extend a pair-sum problem and reason through a grid traversal, then assess your explanations and failure cases without claiming current employer question-frequency data.
- 63
Senior-Flavour Coding
Coding and design exercises for LRU caches, hit counters, logging limits, queues, and ring-based key routing.
- 64
Contest Simulation
A timed contest simulation with explicit triage, scoring, recovery, and post-session review rules.
- 65
Final Audit + Maintenance Plan
Re-audit patterns against an earlier baseline and schedule bounded maintenance, repair, and follow-up checks.
- 66
Variant contracts: bounded budgets, interval cuts and subset routes
Extend the restored problem-family series with bounded knapsack, two resource budgets, interval reconstruction and Held–Karp routes, using independent tiny oracles.