← Interview home
Interview Prep · Pattern Reference

LeetCode Patterns

A visual, example-driven catalog of the recurring patterns behind LeetCode problems — each with recognition triggers, the core trick, worked examples, and clean code. Built for fast review before interviews.

18 guides · C++ & Python · dark / light · works offline

Start here

00Master ReferenceMaster taxonomy of every pattern family, priority tiers, and how these guides fit together.Master reference

Arrays, Strings & Hashing

01Arrays & StringsPrefix sums, difference arrays, cyclic sort, in-place rearrangement, intervals, canonical-key hashing.C++ · 10 patterns 02Hash Map / Hash SetComplement lookups, frequency counting, canonical keys, prefix-sum maps, the array as its own map.C++ · 9 patterns 03Two / Three / N PointersConverge, chase, and parallel pointers — k-sum, reader/writer, Floyd, Dutch flag, expand-from-center.Python · 10 patterns 04Sliding WindowFixed and variable windows: longest / shortest / count, budgets, monotonic deque, rolling hash.C++ · 8 patterns

Search & Selection

05Binary SearchBoundary search, rotated arrays, peaks, binary search on the answer, and implicit search spaces.C++ · 11 patterns 17Searching & SelectionBinary search variants, quickselect, and search in rotated / 2-D structures.Python · 6 patterns

Linked Lists

06Linked ListsReversal, fast/slow, gap walks, merge sort, the middle+reverse+merge combo, and LRU design.C++ · 10 patterns

Trees & Graphs

07Trees & BSTsDFS / BFS traversals, tree DP, BST properties, LCA, tries, and serialize / deserialize.C++ · 11 patterns 10GraphsBFS / DFS, topological sort, union-find, shortest paths, MST, and bipartite checks.C++ · 11 patterns

Heaps & Backtracking

08Heap / Priority QueueTop-K, merge-K sorted, two-heaps median, and heap-driven scheduling.Python · 11 patterns 09BacktrackingSubsets, combinations, permutations, constraint satisfaction, and grid / partition enumeration.C++ · 9 patterns

Dynamic Programming

111D Dynamic ProgrammingOne-dimensional decision DP — the core recurrences behind stairs, house robber, coin change.C++ · 9 patterns 12Advanced DP (2D and Beyond)Knapsack, LIS / LCS, grid, interval, bitmask, tree, and digit DP.C++ · 12 patterns

Greedy & Math

13GreedyInterval scheduling, jump games, exchange arguments, and Huffman-style greedy.Notes · 11 patterns 14Math & Number TheoryGCD / LCM, sieves, modular exponentiation, bit tricks, and number-theory staples.Python · 14 patterns 15CombinatoricsCounting, binomial coefficients, stars and bars, and Catalan structures.Python · 9 patterns 16Probability & RandomnessExpected value, linearity, randomized algorithms, and reservoir sampling.Python · 6 patterns
Tip: start with the Master Reference, then follow the groups top-to-bottom. Each guide has its own study order at the bottom.