Algorhythm — Train the pattern. Practice on LeetCode.<br>Train the pattern first.<br>Then practice on LeetCode.<br>We are not another problem archive. We compress the gap between I read the problem and I see the trick from hours into minutes — with interactive animations that teach the mental model, not the syntax.
Two Pointers<br>Two indices moving over the same sequence to maintain an invariant — converging, fast/slow, sliding window.
converging · fast-slow · sliding
Binary Search Variants<br>Boundary conditions are the field's largest unsolved teaching problem.
3 variants · O(log n)
Backtracking<br>Decision-tree expansion — uniquely suited to animation.
branching state machine
Monotonic Stack<br>Stack-state transitions are invisible in code, dramatic in animation. The stack is the protagonist.
next-greater · histogram
BFS / DFS on Gr DFS<br>A queue gives breadth, a stack gives depth — same algorithm, two traversal orders.
queue · stack · flood fill
Heap & Priority Queue<br>Cheap access to the extreme — min or max — while everything else stays loosely ordered. A family of three sub-patterns: top-k, two heaps, k-way merge.
top-k · two-heaps · k-way-merge
Tree Traversal<br>Every traversal visits every node once — only when relative to children's recursion differs.
preorder · inorder · postorder · level
Linked List Manipulation<br>Three pointers — prev, curr, next — let you rewrite a list in place without losing the tail.
reverse · merge · reorder
Dynamic Programming<br>A table fills itself, one cell at a time — each entry composed from a constant number of earlier ones. A family of seven sub-patterns.
1-d · 2-d · knapsack · interval · state-machine · tree · bitmask
Union Find<br>Maintain a partition of N elements into disjoint components — merge two components in near-constant time, with the forest flattening itself on every query.
connected components · O(α(N))
Trie<br>Store a set of strings on a tree of characters — words that share a prefix share a path, and a single 'end-of-word' flag separates stored words from in-flight prefixes.
prefix queries · autocomplete · word-search
Topological Sort<br>Linearize a directed acyclic graph so every edge points left-to-right — each node enters the order only after every prerequisite has already left.
Kahn's algorithm · O(V + E) · cycle detection
Prefix Sum<br>Pay O(N) once to amortize every range query to O(1) — and flip it inside-out for cheap range updates. A family of four sub-patterns.
1-d · 2-d · difference · hash-map
Shortest Path<br>Find the shortest route from a source — the mechanism splits by what the edges carry. BFS for uniform costs, Dijkstra for non-negative, Bellman-Ford for negatives, Floyd-Warshall for all pairs.
BFS · Dijkstra · Bellman-Ford · Floyd-Warshall
Merge Intervals<br>Sort by start, then sweep — each interval either extends the current merge or commits it and starts a new one. The whole pattern lives in that one comparison.
sort + linear sweep · O(N log N)
Bit Manipulation<br>Treat integers as their bits, not their values — XOR a number against itself to zero it, against zero to keep it. The trick is recognizing when a problem has a hidden bit-level structure.
XOR · bit mask · O(N)
⊕=<br>Cyclic Sort<br>When values live in [0, N] or [1, N], the index IS the pointer — swap to home or sign-flip to mark seen. Missing/duplicate problems collapse to O(N) time, O(1) space.
index-as-pointer · O(N)
Sweep Line<br>Turn each interval into a +1 event at its start and a −1 event at its end, sort by position, then sweep. The running active count rises and falls — its peak is the answer for max-concurrent problems.
endpoint events · running max · O(N log N)
Greedy<br>At every step, take the locally optimal commit — and prove it never gets undone. No backtracking, no DP table.
interval-scheduling · jump-game · gas-station
Segment Tree<br>A balanced binary tree whose nodes hold range aggregates. Any range decomposes into O(log N) canonical pieces — so queries and point updates are both O(log N).
range query · point update · O(log N)
Fenwick Tree<br>An implicit tree via the lowest set bit — O(log N) point updates and prefix sums in ten lines of code, no nodes to allocate.
implicit tree · lowbit · O(log N)
String Matching<br>Find P inside T in O(N + M) instead of O(N·M). Three sub-patterns differ only in what they precompute from the pattern: failure function, rolling hash, or Z-array.
kmp · rabin-karp · z-algorithm
Matrix<br>A 2-D coordinate space with two indices. The trick is the walk order — transpose+reverse, perimeter shrink, or monotone-corner staircase.
rotate · spiral · staircase-search
Math & Number Theory<br>Recognize the number-theoretic structure (divisibility, modular, multiplicative) and an O(N) loop collapses to O(log N) or O(N log log N).
gcd-lcm · modular-power · prime-sieve
Minimum Spanning Tree<br>Cheapest way to connect every node of a weighted graph — exactly N−1 edges, no cycles, minimum total weight.
kruskal · prim
Cache Eviction<br>Fixed-capacity store with O(1) get and...