Algorithm patterns for coding interviews
Most interview problems are a handful of patterns in disguise. Learn the signals that point to each one, then practice on real LeetCode problems with interactive, step-by-step lessons.
Sliding Window
Turn nested-loop scans of contiguous ranges into linear time.
Two Pointers
Walk a sorted array from both ends to skip impossible work.
Binary Search
Halve the search space every step — including on answers, not just arrays.
Dynamic Programming
Break a problem into overlapping subproblems and reuse the answers.
Backtracking
Explore every choice, undo, and prune the dead ends.
Graph Traversal (BFS & DFS)
Visit every node once — breadth-first for shortest paths, depth-first for structure.
Topological Sort
Order tasks so every dependency comes before what needs it.
Union-Find (Disjoint Set)
Merge and query connectivity in near-constant time.
Heap / Priority Queue
Always pull the smallest or largest element in log time.
Monotonic Stack
Keep a stack in sorted order to find next-greater elements in one pass.
Prefix Sums
Precompute running totals to answer range queries in O(1).
Hashing & Frequency Maps
Trade memory for O(1) lookups, counts, and dedupe.
Fast & Slow Pointers
Two speeds through a sequence to find cycles and midpoints.
Intervals
Sort by start, then sweep to merge or schedule overlaps.