Algorithm & Data Structure Cheat Sheets

133 sheets, grouped by topic and ranked by how often the pattern actually shows up in a FAANG software-engineering loop. Read the Start here ladder first; the catalogue below is for lookup.

What the stars mean

  • Priority 5 of 5 — Must know — expect it in almost every loopMust knowShows up in almost every FAANG loop — you should be able to write these from memory.
  • Priority 4 of 5 — High value — a gap here costs you roundsHigh valueCommon enough that a gap here costs you rounds.
  • Priority 3 of 5 — Worth knowing — usually a variant of a must-know patternWorth knowingAppears regularly, usually as a variant of a tier-5 pattern.
  • Priority 2 of 5 — Niche — read once, revisit only if a company is known to askNicheRare in interviews — read once, revisit only if a target company is known to ask.

The same stars appear on individual sections inside each sheet, so you can skim a 4,000-line doc and still see which templates are the ones to memorise.

Start here

12 sheets in reading order. Together they cover the large majority of what a coding round will actually ask.

  1. LeetCode Pattern GuidePriority 5 of 5 — Must know — expect it in almost every loopTriage: given a problem, which pattern does it want?
  2. Complexity Cheat SheetPriority 5 of 5 — Must know — expect it in almost every loopYou will be asked to state complexity in every round.
  3. ArrayPriority 5 of 5 — Must know — expect it in almost every loopIn-place rewriting and the index-as-hash trick.
  4. Hash MapPriority 5 of 5 — Must know — expect it in almost every loopThe single most-used structure in interviews.
  5. Two PointersPriority 5 of 5 — Must know — expect it in almost every loopConverging and trailing pointers on arrays/strings.
  6. Sliding WindowPriority 5 of 5 — Must know — expect it in almost every loopExpand/contract on a condition — a whole question family.
  7. Binary SearchPriority 5 of 5 — Must know — expect it in almost every loopBoundary templates, plus binary search on the answer.
  8. Binary TreePriority 5 of 5 — Must know — expect it in almost every loopHow DFS state flows down and back up a tree.
  9. BFS (Breadth-First Search)Priority 5 of 5 — Must know — expect it in almost every loopLevel order, and why it gives shortest paths.
  10. DFS (Depth-First Search)Priority 5 of 5 — Must know — expect it in almost every loopThe recursion patterns every graph/tree question reuses.
  11. Heap & Priority QueuePriority 5 of 5 — Must know — expect it in almost every loopTop-k and "repeatedly take the best" problems.
  12. Dynamic Programming (DP)Priority 5 of 5 — Must know — expect it in almost every loopThe largest and hardest tier-5 block — budget the most time here.

Full catalogue

Arrays & Strings21 sheets

The highest-frequency surface in any interview loop. Master the four pattern families here before anything else.

Array

Priority 5 of 5 — Must know — expect it in almost every loop

Array fundamentals — in-place rewriting, rotation, partitioning, and the index-as-hash trick. Owns the operations; the pattern families (windows, pointers, prefix sums) each have their own file.

Sliding Window

Priority 5 of 5 — Must know — expect it in almost every loop

Windows that grow and shrink on a condition — fixed-size, variable-size, at-most-k, and exactly-k by subtraction; owns the expand/contract loop and the six canonical window templates.

Strings

Priority 5 of 5 — Must know — expect it in almost every loop

The everyday string catalogue — character-level two-pointer scans, frequency and anagram signatures, run-length grouping, tokenising, parsing and in-place rewriting — while the worked-solution archive, the language-level string API, palindromes, substring search and two-sequence DP each live in their own sheet.

Two Pointers

Priority 5 of 5 — Must know — expect it in almost every loop

The two-pointer family on arrays and strings — opposite-ends convergence, fast/slow, expand-from-centre and the read/write partition, with one canonical template for each; window problems that grow and shrink on a condition live elsewhere.

Array — Worked Examples

Priority 4 of 5 — High value — a gap here costs you rounds

The worked-solution archive behind array.md: thirteen problems that are genuinely about rewriting an array in place or using its indices as storage, grouped by the trick each one turns on.

Matrix — Worked Examples

Priority 4 of 5 — High value — a gap here costs you rounds

The worked-solution archive behind matrix.md: seventeen problems grouped by the geometry or technique each one turns on — traversal order, in-place transformation, staircase search, grid search, 2D DP, and row-pair compression.

Matrix / 2D Grid

Priority 4 of 5 — High value — a gap here costs you rounds

The 2D grid as its own topic — traversal geometry (spiral, diagonal, rotate, transpose), in-place marking, and index↔coordinate arithmetic.

N Sum (2Sum → kSum)

Priority 4 of 5 — High value — a gap here costs you rounds

The k-sum family specifically — 2Sum through kSum, the sort-then-converge recursion, and duplicate handling.

Palindrome

Priority 4 of 5 — High value — a gap here costs you rounds

The palindrome family — expand-from-center, two-pointer verification, palindromic DP, and Manacher — and how to tell which a problem needs.

Prefix Sum

Priority 4 of 5 — High value — a gap here costs you rounds

Prefix / running sums — subarray sums, 2D prefix sums, prefix + hashmap counting.

Prefix Sum — Advanced Templates

Priority 4 of 5 — High value — a gap here costs you rounds

The six prefix-sum templates that borrow another structure or another identity: the complement trick, the monotonic deque for arrays with negatives, row-pair compression for 2D, prefix XOR, the sparse difference array via a hash map, and the prefix-sum-on-a-tree counting map.

Sliding Window — Advanced Window Shapes

Priority 4 of 5 — High value — a gap here costs you rounds

The sliding-window techniques a first pass should skip: deque-maintained window extrema, the at-most-K-distinct family, exactly-K counting beyond one worked instance, and the windows whose key is not a character — complement, word-level chunks, index-bounded value buckets and sorted intervals; the six must-know templates stay in the main sheet.

Sliding Window — Worked Examples

Priority 4 of 5 — High value — a gap here costs you rounds

The worked sliding-window LeetCode catalogue, one canonical solution per problem per language, each filed under the template it instantiates; the templates, the concepts and the decision tables stay in the main sliding-window sheet.

String Algorithms — Worked Examples

Priority 4 of 5 — High value — a gap here costs you rounds

The worked string LeetCode archive, one canonical solution per problem per language, each filed under the parent sheet's template that it instantiates; the concepts, the pattern catalogue and the templates themselves stay in the main string sheet.

Two Pointers — Worked Examples

Priority 4 of 5 — High value — a gap here costs you rounds

The worked two-pointer LeetCode catalogue, one canonical solution per problem per language, grouped by the template it instantiates; the concepts, pointer types and templates themselves stay in the main two-pointer sheet.

Addition (Strings, Ints, Lists)

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

Digit-by-digit addition across the four input shapes an interviewer will hand you: strings, integers, arrays, and linked lists.

Difference Array

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

O(1) range update, O(n) rebuild — the inverse of a prefix sum.

Prefix Sum — Worked Examples

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

The worked-solution archive behind prefix_sum.md: the eight problems the templates do not already solve end to end, grouped by which prefix-sum shape they need.

String Matching (KMP, Rolling Hash)

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

Substring search only — KMP's failure function, Rabin-Karp rolling hash, and the built-in-indexOf-vs-KMP-vs-hash decision.

String Operations & Language APIs

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

The language mechanics of strings: Python slicing and methods, Java String and StringBuilder, character classification and case conversion, char arithmetic, the split/join traps and the build-performance rules — not the algorithms that use them.

Advanced String Algorithms

Priority 2 of 5 — Niche — read once, revisit only if a company is known to ask

Heavier string machinery — suffix structures, Z-algorithm, Manacher, and string-DP — the parts too specialised for the main string doc.

Hashing, Stacks & Queues12 sheets

O(1) lookup and LIFO/FIFO discipline — the structures that turn an O(n^2) scan into O(n).

Hash Map

Priority 5 of 5 — Must know — expect it in almost every loop

Key→value problem patterns — lookup, grouping, index maps, prefix-sum maps, remapping.

Stack

Priority 5 of 5 — Must know — expect it in almost every loop

LIFO fundamentals and the canonical stack templates: bracket matching, min-stack, the short monotonic-stack form, explicit-stack traversal and the scope/context ledger.

Hash Map — Worked Examples

Priority 4 of 5 — High value — a gap here costs you rounds

The worked-solution archive for the hash-map family: one canonical solution per problem, the pattern-specific templates that are really single-problem deep dives, and the ordered-map (Java TreeMap / Python SortedDict) reference.

Java Collections — Which to Use

Priority 4 of 5 — High value — a gap here costs you rounds

Cross-collection chooser — which Java / Python container for which job, and the API gotchas of each.

Monotonic Stack

Priority 4 of 5 — High value — a gap here costs you rounds

Next greater / previous smaller / span / histogram problems — the stack stays sorted so each element is pushed and popped once.

Queue Data Structure

Priority 4 of 5 — High value — a gap here costs you rounds

FIFO fundamentals — BFS queues, deques, circular buffers, queue-backed designs.

Stack — Expression Parsing

Priority 4 of 5 — High value — a gap here costs you rounds

The stack-based expression family: the calculators (LC 224 / 227 / 772), decode-string style nesting (LC 394) and postfix / sequential-operand evaluation (LC 150, 682), with the pre_op delay-insert trick that makes operator precedence fall out of a plain stack.

Stack — Worked Examples

Priority 4 of 5 — High value — a gap here costs you rounds

The worked-solution archive behind stack.md: one canonical solution per problem per language for the monotonic, greedy-removal, adjacent-duplicate, bracket-family, traversal and design problems, grouped by the template each one exercises.

Hashing & Counting

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

Hashing internals and counting idioms — hash design, collisions, frequency maps, rolling hash, custom keys.

Monotonic Queue (Deque)

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

Sliding-window max/min in O(1) amortised, using a deque that stays monotonic.

Set

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

Membership, dedup and set algebra — problems where you only need presence, not an associated value.

Set — Worked Examples

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

The worked-solution archive behind set.md: fourteen problems grouped by what the set is being used for — a memory of what has been seen, set algebra, an O(1) index that replaces a scan, or a component inside a larger algorithm.

Linked Lists3 sheets

Pointer surgery. Low conceptual depth, high implementation-precision bar.

Linked List

Priority 5 of 5 — Must know — expect it in almost every loop

Pointer surgery on singly and doubly linked lists — reversal, merging, reordering, dummy-head technique, and cycle handling.

Linked List — Worked Examples

Priority 4 of 5 — High value — a gap here costs you rounds

The worked-solution archive behind linked_list.md: one canonical solution per problem per language for the reversal, merging, splitting, copying, flattening and list-sorting problems, grouped by the technique each one exercises.

Two Pointers — Linked List

Priority 4 of 5 — High value — a gap here costs you rounds

Two pointers over linked-list nodes — fast/slow cycle detection, middle finding, k-th from end, and offset pointers. No array indexing.

Trees & Heaps18 sheets

Recursive structure plus ordered access. Roughly a quarter of all tree/heap-tagged interview questions come from these five sheets.

Binary Tree

Priority 5 of 5 — Must know — expect it in almost every loop

Binary-tree-specific reasoning: which direction DFS state flows (down vs up), plus the 11 structural templates built on that.

BST (Binary Search Tree)

Priority 5 of 5 — Must know — expect it in almost every loop

Ordered trees only — what the left < root < right invariant buys you (O(log n) search, sorted inorder, range pruning, order statistics).

Heap & Priority Queue

Priority 5 of 5 — Must know — expect it in almost every loop

Both the heap (the structure) and the priority queue (the ADT it implements), in Python and Java. Formerly split across heap.md + priority_queue.md, which solved the same problems twice.

Tree — Concepts & Patterns

Priority 5 of 5 — Must know — expect it in almost every loop

Tree concepts, tree types and traversal-order strategy — the why and which, plus the advanced techniques that are not per-pattern templates (Morris threading, binary lifting, re-rooting). The templates themselves live in tree2.md.

Tree LCA, Distance & Path Problems

Priority 5 of 5 — Must know — expect it in almost every loop

Lowest common ancestor, node-to-node distance, parent-map (bidirectional) traversal and the root-to-leaf path templates — every tree problem whose answer is a path or a meeting point rather than a shape.

Advanced Heap Techniques

Priority 4 of 5 — High value — a gap here costs you rounds

The heap patterns a first pass should skip: lazy deletion, sweep-line "alive" heaps, regret greedy, resource-pool allocators, grid best-first search, and the structures beyond a plain binary heap; the six must-know templates stay in the parent sheet.

BST — Advanced Patterns & Deep Dives

Priority 4 of 5 — High value — a gap here costs you rounds

The BST material a first pass should skip: order-statistic (rank) queries, the lazy O(h)-space iterator, in-order drop detection for a corrupted BST, the full construction-variant catalogue, and the detach/bounds variations that go beyond the canonical delete and validate templates.

BST — Worked LeetCode Examples

Priority 4 of 5 — High value — a gap here costs you rounds

The worked-solution archive for the BST templates taught in bst.md — one canonical solution per problem per language — plus the root-to-leaf and node-to-node path family that is filed with BST but needs no ordering at all.

Heap — Worked LC Examples

Priority 4 of 5 — High value — a gap here costs you rounds

The worked-solution archive for the heap / priority-queue family: one canonical solution per problem per language, with the reasoning, traces and gotchas written out in full.

Tree Construction

Priority 4 of 5 — High value — a gap here costs you rounds

Building a binary tree from something flat: two traversal arrays, an index range over one array, or a parenthesised / infix string — the inverse direction of every tree problem that only reads a tree.

Tree Pattern Templates

Priority 4 of 5 — High value — a gap here costs you rounds

A numbered, copy-paste template per tree pattern, in Python and Java — the single home for tree templates. Template-first, no theory: which traversal a problem wants is tree.md's question.

Tree Serialization & String Codec

Priority 4 of 5 — High value — a gap here costs you rounds

Turning a tree into a string and back — subtree fingerprints for identity and duplicate detection, and the full encode/decode codec family (parenthesis, comma plus null marker, depth prefix).

Trie

Priority 4 of 5 — High value — a gap here costs you rounds

The prefix tree — insert/search/startsWith, node layout choices, and the problems where sharing prefixes is the whole trick (autocomplete, word search, XOR trie).

Heap Language APIs (heapq / PriorityQueue)

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

The language mechanics of heaps: every heapq and PriorityQueue call you need, how to fake a max-heap, how to peek without popping, and the traps that come with a partially-ordered container; the algorithms that use them live in the heap sheets.

Tree — Worked LeetCode Examples

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

The worked-solution archive for the tree patterns taught elsewhere: one canonical solution per problem per language, grouped by what the problem asks for rather than by technique.

Tree Backtracking (Root→Leaf Paths)

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

Root→leaf path problems where the path itself is the state and must be undone on the way back up.

Trie — Worked Examples

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

The worked-solution archive behind trie.md: five problems, from building the structure to the grid search where a trie turns "once per word" into one walk.

Priority Queue → see Heap

Priority 2 of 5 — Niche — read once, revisit only if a company is known to ask

Redirect only. This file has been merged into heap.md; it exists to point old links at the right sections.

redirect

Graphs19 sheets

Traversal, connectivity and ordering. BFS/DFS are must-know; the weighted shortest-path trio is mostly L5+ territory.

BFS (Breadth-First Search)

Priority 5 of 5 — Must know — expect it in almost every loop

The main BFS reference: the queue templates, level-by-level expansion, grid and multi-source BFS, and why first visit equals shortest path on an unweighted graph; the heavier variants and the long tail of worked problems live in their own sheets.

DFS (Depth-First Search)

Priority 5 of 5 — Must know — expect it in almost every loop

The main DFS reference: the ten core depth-first templates — tree traversal, grid flood fill, path finding, backtracking, tree modification, post-order aggregation, boundary elimination, shape signatures and weighted-edge traversal — with the recognition table that picks between them.

Graph Algorithms

Priority 5 of 5 — Must know — expect it in almost every loop

Graph representation, traversal, connectivity, cycle detection and the general graph-problem catalogue.

Dijkstra — Worked Examples

Priority 4 of 5 — High value — a gap here costs you rounds

The worked-solution archive behind Dijkstra.md: eleven problems in both languages, grouped by the shape of the search state, since that is what decides whether you need dist[], a second state dimension, or a plain visited[].

Dijkstra’s Algorithm

Priority 4 of 5 — High value — a gap here costs you rounds

Single-source shortest path with non-negative weights, via a priority queue.

Topological Sort

Priority 4 of 5 — High value — a gap here costs you rounds

Ordering a DAG — Kahn's BFS, DFS post-order, cycle detection, and the scheduling problems built on them.

Topological Sorting — Worked Examples

Priority 4 of 5 — High value — a gap here costs you rounds

The worked-solution archive behind topology_sorting.md: eight problems in both languages, grouped by the shape of the dependency they encode rather than by problem number.

Union Find (Disjoint Set)

Priority 4 of 5 — High value — a gap here costs you rounds

Disjoint set union — connectivity, component counting, cycle detection in undirected graphs, with path compression and union by rank.

Advanced Graph Algorithms

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

The graph techniques a first interview pass should skip: Tarjan's low-link family (strongly connected components, bridges, articulation points), Euler paths and circuits, max flow / min cut, and the bipartite extras — Union-Find detection, maximum matching and greedy k-colouring.

BFS — Advanced Variants

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

The BFS techniques a first pass should skip: bidirectional BFS, 0-1 BFS with a deque, multi-source beyond the canonical template, BFS over implicit state spaces, and all-shortest-path DAG enumeration — the must-know queue templates stay in the main sheet.

BFS — Worked LeetCode Examples

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

The worked-solution archive for BFS: one canonical solution per grid, state-space, tree-mutation and leaf-trimming problem, plus the LC 994 walkthrough on where to increment time — it teaches no new templates.

DFS — Advanced Patterns

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

The rare and hard DFS techniques a first pass should skip: two-grid validation, edge-direction tracking, cross-component pair counting, Euler paths, Tarjan low-link bridges, trie-backed wildcard search, depth-indexed stack DFS, and the post-order rollups on N-ary and parent-array trees.

DFS — Worked Examples

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

The worked-solution archive for dfs.md: one canonical solution per problem for the DFS problems the core templates cover, plus the pattern-and-difficulty index of the whole DFS problem set.

Graph Worked Examples

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

The worked-solution archive for graph.md: one canonical solution per problem for the grid, clone, connectivity, ratio-graph, implicit-DAG and DSU-by-attribute problems, with no template or theory material of its own.

Shortest Path — Which Algorithm?

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

Decision doc only — which shortest-path algorithm for which problem shape, and where the naive choice is wrong. No full implementations.

Topological Sort vs Union Find

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

Decision doc only — topological sort vs union-find: what each answers, where the naive choice is wrong, and problems solvable by both.

Union Find — Worked Examples

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

The worked-solution archive behind union_find.md: nineteen problems grouped by what a node represents — a vertex, a grid cell, a variable carrying a ratio, or a tree node — since that is the only thing that changes between them.

Bellman-Ford Algorithm

Priority 2 of 5 — Niche — read once, revisit only if a company is known to ask

Single-source shortest path that tolerates negative weights, and detects negative cycles. Also the k-hop-bounded variant.

Floyd-Warshall Algorithm

Priority 2 of 5 — Niche — read once, revisit only if a company is known to ask

All-pairs shortest path by DP over intermediate vertices — O(V³), dense graphs, transitive closure.

Search & Sort7 sheets

Halving a monotonic space, and what sorting buys you. Binary search on the answer is the single most under-practised tier-5 skill.

Binary Search

Priority 5 of 5 — Must know — expect it in almost every loop

Halving a monotonic search space — the loop-invariant reasoning behind l <= r vs l < r, the boundary (lower/upper bound) templates, rotated arrays, and floating-point and 2D search.

Binary Search on the Answer

Priority 5 of 5 — Must know — expect it in almost every loop

Binary searching a range of candidate answers against a monotone feasibility predicate — the canFinish / isValid framing, the minimise-maximum vs maximise-minimum decision, the [max(nums), sum(nums)] boundary recipe, and counting predicates over a value domain.

Binary Search — Worked Examples

Priority 4 of 5 — High value — a gap here costs you rounds

The worked-problem archive for binary_search.md — one canonical solution per problem for the index-space templates, with the traces and pitfalls that do not fit on the main sheet.

Patience Sorting (LIS)

Priority 4 of 5 — High value — a gap here costs you rounds

The card-game algorithm behind O(N log N) longest increasing subsequence: the piles, the tails array they collapse to, recovering the subsequence itself, and the problem family that reduces to it.

QuickSelect (Kth Element by Partition)

Priority 4 of 5 — High value — a gap here costs you rounds

Partition-based selection: finding the Kth largest, Kth smallest or K closest element in O(n) average time by recursing into only one side of a QuickSort partition, including pivot strategies and an outline of the O(n) worst-case Median of Medians.

Sorting Algorithms

Priority 4 of 5 — High value — a gap here costs you rounds

Sorting algorithms and sort-adjacent techniques — comparison sorts and their stability, counting/bucket/radix, quickselect, custom comparators, and cyclic sort.

Divide & Conquer (Advanced)

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

Divide-and-conquer beyond merge sort — the recursion-with-merge shapes (count-while-sorting, closest pair, matrix D&C, D&C on expressions) and their recurrences.

Dynamic Programming & Recursion18 sheets

The hardest tier-5 block. Start from recursion, memoise, then tabulate.

0/1 背包 DP(中文)

Priority 5 of 5 — Must know — expect it in almost every loop

用中文把 0/1 背包從「物品重量價值」一路講到 LC 494/416 的解題流程,重點放在 state 怎麼定義、「拿或不拿」的轉移、以及為什麼內層 loop 一定要倒序;完全背包(Unbounded)與排列/組合的 loop 順序規則不在這裡展開。

Backtracking

Priority 5 of 5 — Must know — expect it in almost every loop

Systematic search with undo: the choose/explore/un-choose skeleton, start_idx control, duplicate skipping, pruning, and exactly one canonical template per must-know shape — the long tail of worked solutions and the hard-tier state-carrying templates live in its two satellites.

Dynamic Programming (DP)

Priority 5 of 5 — Must know — expect it in almost every loop

The main DP sheet — state design, the pattern catalogue, and one canonical template per must-know DP family; the worked-solution archive, the rare techniques, and the five heaviest sub-topics live in their own sheets and are linked from here.

Knapsack DP

Priority 5 of 5 — Must know — expect it in almost every loop

The knapsack family in full: 0/1 vs unbounded vs bounded vs group, the subset-sum reduction, why the 0/1 inner loop runs backward, and the loop-order rule that separates combinations from permutations.

Advanced Backtracking

Priority 4 of 5 — High value — a gap here costs you rounds

Hard-tier backtracking that carries extra state through the recursion — a Trie node, the previous operand, a deletion budget — plus constraint propagation, memoised search and the generic partitioning templates a first pass should skip; none of the must-know shapes are repeated here.

Advanced DP Techniques

Priority 4 of 5 — High value — a gap here costs you rounds

The DP appendix — techniques a first pass should skip: game-theory / minimax DP, tree and re-rooting DP, interval and string DP deep dives, probability and step-indexed counting DP, monotonic-queue and stack-carried DP, and the long-form derivations trimmed out of the main sheet.

DP Loop Order & Dependency

Priority 4 of 5 — High value — a gap here costs you rounds

Why a bottom-up DP's loop nesting and direction are forced by its own transition, the four ways a wrong order fails, and LC 139 Word Break worked in five orders — including the one that looks right, passes "leetcode", and silently fails the problem's own Example 2.

DP Patterns — One-Screen Templates

Priority 4 of 5 — High value — a gap here costs you rounds

Template index — one short section per classic DP pattern (Kadane, LIS, MCM, LCS, knapsack, state machine, grid, bitmask, digit, tree DP, regex, interval scheduling, split, memoised DAG).

Recursion

Priority 4 of 5 — High value — a gap here costs you rounds

Recursion as a mechanism — base case, state passed down vs returned up, call-stack cost, and converting to iteration. The pattern families that use recursion each have their own file.

Recursion → DP

Priority 4 of 5 — High value — a gap here costs you rounds

The mechanical pipeline: recursion → memoisation → tabulation → space-optimised, applied to one problem at a time.

String DP

Priority 4 of 5 — High value — a gap here costs you rounds

DP over one or two strings: the dp[m+1][n+1] two-sequence grid, prefix-based (1-indexed) table design, and the worked patterns for LCS, edit distance, interleaving and wildcard/parenthesis matching.

Backtracking — Worked LC Examples

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

The long tail of worked backtracking solutions (LC 17, 39, 79, 78, 90, 77, 46, 22, 93, 139, 140, 207) with their recursion traces and near-miss variations, one canonical solution per problem per language — it teaches no templates of its own, every section points back to the one it instantiates.

Bitmask DP

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

DP where the state is a subset encoded in an integer: mask operations, submask enumeration, TSP and assignment templates, and the n <= 20 sizing rule.

DP Worked Examples

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

The worked-solution archive behind dp.md: one canonical Java / Python solution per classic DP problem plus the problems-by-pattern index, with no templates or theory of its own.

Kadane's Algorithm

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

The maximum-subarray family in depth — Kadane and its variants (product, circular, with deletion, 2D).

Monotonic Stack + DP

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

Problems where a monotonic stack carries a DP value: "how many rounds does this element survive", largest-rectangle-style area DP, and the maximal-square / count-squares grid recurrences.

Stock Trading (State Machine DP)

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

The LC 121/122/123/188/309/714 buy-and-sell family, unified under one dp[i][k][hold] state machine.

Digit DP

Priority 2 of 5 — Niche — read once, revisit only if a company is known to ask

Counting how many numbers in a range satisfy a digit-level property: the tight/started/position state, the universal top-down template, and the count(R) - count(L-1) range trick.

Greedy & Intervals6 sheets

Sort-then-scan, and the exchange argument that proves it correct.

Greedy Algorithms

Priority 4 of 5 — High value — a gap here costs you rounds

Taking the locally best choice and the exchange argument that proves it safe — interval scheduling, jump games, task assignment — plus how to spot when greedy fails and DP is required.

Intervals

Priority 4 of 5 — High value — a gap here costs you rounds

Sort-then-merge interval problems — merge, insert, count overlaps, minimum removals.

Greedy — Worked Examples

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

The worked-solution archive behind greedy.md: fourteen problems grouped by the shape of the greedy choice — extend a reach, accumulate and reset, interleave by frequency, sort and take, or commit while scanning.

Sweep Line

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

Line sweep — turn each interval into +1 / -1 events, sort by coordinate, sweep once.

Sweep Line — Worked Examples

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

The worked-solution archive behind scanning_line.md: six problems grouped by what the sweep is actually counting — overlap depth, a weighted sum, a heap of live jobs, or the intersection of two sorted lists.

Interval Overlap Predicate

Priority 2 of 5 — Niche — read once, revisit only if a company is known to ask

One idea only — the interval-overlap predicate: closed [a,b] vs half-open [a,b), and which one each LC problem needs.

Range Queries & Advanced Structures4 sheets

Reach for these only when a problem needs updates *and* range queries — otherwise a prefix sum is enough.

Binary Indexed Tree (Fenwick)

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

The Fenwick tree specifically — i & -i index arithmetic, point update + prefix query, and the problems it is the tidiest answer to.

Segment Tree

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

Range query + range update structures — the segment tree, lazy propagation, and the BIT-vs-segment-tree-vs-merge-sort decision.

Algorithms Under a Memory Cap

Priority 2 of 5 — Niche — read once, revisit only if a company is known to ask

What to do when the input does not fit in RAM: bit vectors, bucket-then-refine passes, sharding a file by hash, and external merge sort — the techniques that still return an exact answer by paying with extra passes.

Streaming Algorithms

Priority 2 of 5 — Niche — read once, revisit only if a company is known to ask

Algorithms constrained to one pass and sub-linear memory — reservoir sampling, Boyer-Moore majority, weighted random pick, and approximate counting.

Math & Bits5 sheets

Small, self-contained topics. Cheap to learn, occasionally decisive.

Bit Manipulation

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

How integers are represented in bits (two's complement, fixed width, shifts) and the operations and tricks built on that — masks, XOR identities, lowest set bit, subset enumeration, and bitmask DP.

Bit Manipulation — Worked Examples

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

The worked-solution archive behind bit_manipulation.md: nineteen problems grouped by which property of the bit operators they lean on — XOR cancelling pairs, clearing the lowest set bit, carry-free arithmetic, an integer standing in for a subset, or a hand-built mask editing a bit field.

Math

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

Numeric manipulation in interviews — digit extraction, overflow-safe arithmetic, base conversion, roots, and pow. Formula-level counting lives next door.

Combinatorics & Number Theory

Priority 2 of 5 — Niche — read once, revisit only if a company is known to ask

Counting and number theory as they appear in interviews — modular arithmetic, GCD/LCM, sieves, nCr, reservoir sampling, and basic geometry.

Math & Logic Puzzles

Priority 2 of 5 — Niche — read once, revisit only if a company is known to ask

The four moves that solve brainteaser-style questions: counting how much information one test buys, balancing the worst case, finding the invariant, and using linearity of expectation. It teaches the moves, not a riddle list.

Design & Simulation7 sheets

"Design a X" and low-level-design rounds — judged on operation complexity and class modelling, not cleverness.

Design — Worked Examples

Priority 4 of 5 — High value — a gap here costs you rounds

The worked-solution archive behind design.md: twenty LC "design a X" problems in full, grouped by the structure pair each one forces rather than by problem number.

Design (LC "Design a X")

Priority 4 of 5 — High value — a gap here costs you rounds

LC "design a X" problems — reading the required operations off the problem and picking the structure combination that makes every one of them O(1) or O(log n); the worked designs themselves live in the examples sheet.

OOD / Low-Level Design

Priority 4 of 5 — High value — a gap here costs you rounds

The low-level-design round — class modelling, SOLID, and the design patterns interviewers actually ask for (strategy, observer, factory, state), with worked designs.

Iterator

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

The iterator contract — hasNext/next with lazy state, flattening, peeking, and merging — one idea, in isolation.

System Design Coding Patterns

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

The distributed-systems patterns that get asked as coding questions — consistent hashing, token-bucket and leaky-bucket rate limiting, and the load-balancing algorithms — with runnable implementations and the trade-offs an interviewer follows up on.

Concurrency (Java)

Priority 2 of 5 — Niche — read once, revisit only if a company is known to ask

The handful of Java concurrency problems that appear at L4+ — ordered printing, producer/consumer, read-write coordination and deadlock avoidance — plus the primitives they need.

Simulation

Priority 2 of 5 — Niche — read once, revisit only if a company is known to ask

Problems where the answer is the faithful step-by-step execution — state machines, robot/grid walks, game rounds, iterative rewriting — plus how to keep such code shrinkable.

Language Toolkit7 sheets

Language mechanics, not algorithms. Read for speed and to stop losing submissions to avoidable traps.

Java Collections & Arrays

Priority 4 of 5 — High value — a gap here costs you rounds

The Java library APIs for holding data: arrays and 2D arrays, lists, maps, queues, heaps, stacks and pairs — how to initialise, copy, iterate and index each one, and the traps in doing so.

Java Strings & Sorting

Priority 4 of 5 — High value — a gap here costs you rounds

Java String and StringBuilder work — converting to and from char[], slicing, parsing, building and mutating — together with everything comparator-shaped: array, collection and map sorting, and the return-value rules that decide the order.

Java Tricks & Idioms

Priority 4 of 5 — High value — a gap here costs you rounds

The Java language semantics that decide whether a correct algorithm produces a correct answer: characters as integers, value vs reference, and integer arithmetic. The library APIs live in two companion sheets.

Python Insertion, Slicing & Index Arithmetic

Priority 4 of 5 — High value — a gap here costs you rounds

The two things that produce most wrong answers in Python solutions that are otherwise correct: where an insertion actually lands, and whether an index range means a count or a distance.

Python Standard Library

Priority 4 of 5 — High value — a gap here costs you rounds

The library-by-library reference: heapq, sortedcontainers, bisect, collections, itertools, functools and datetime — the calls, their complexity, and the idiom each one exists to replace.

Python Tricks & Idioms

Priority 4 of 5 — High value — a gap here costs you rounds

The Python language idioms that come up while solving problems — the cost of the built-in operations, copying, string handling, sort keys, integer arithmetic, comprehensions and scope — grouped by what you are trying to do. The standard library and the index arithmetic have their own sheets.

Python Gotchas

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

Python behaviours that silently cost you a passing submission — mutable defaults, closure late-binding, integer caching, copy semantics — plus the GIL and Python's concurrency story.

Interview Meta6 sheets

How to triage a question and state its complexity. Read before your first mock.

Complexity Cheat Sheet

Priority 5 of 5 — Must know — expect it in almost every loop

Lookup tables — Big-O of every common data structure and classic algorithm, plus the math intuitions behind them.

LeetCode Pattern Guide

Priority 5 of 5 — Must know — expect it in almost every loop

The top-level map: given a problem, which pattern (and therefore which cheatsheet) does it want. Index and triage only — no templates here.

Time & Space Complexity

Priority 4 of 5 — High value — a gap here costs you rounds

Walkthroughs — how to argue the complexity of an actual LC solution, one classic per technique.

Complexity Drills

Priority 3 of 5 — Worth knowing — usually a variant of a must-know pattern

20 self-test drills — read the snippet, state the complexity, check yourself.

Coding Interview Process

Priority 2 of 5 — Niche — read once, revisit only if a company is known to ask

Redirect. The six-step interview loop moved into lc_pattern.md, which is the page you actually open when starting a problem.

redirect

LC Category Index (wisdompeak)

Priority 2 of 5 — Niche — read once, revisit only if a company is known to ask

A pointer to the wisdompeak problem taxonomy, and a map from its 29 categories to the cheatsheet in this repo that teaches each one. The taxonomy itself is not mirrored here.

redirect

How to use this: pick the sheet, read its Scope line to confirm it owns your problem, then jump straight to the starred sections. Every sheet links to its neighbours rather than repeating them.

Source: doc/cheatsheet on GitHub — ratings and grouping live in data/cheatsheet_meta.json.