22 patterns · 79 tagged problems
Sorted by problem count — most common first
Two indices walk a sorted (or paired) structure from different positions to converge on a target.
Maintain a window of elements over a sequence; expand/shrink to satisfy a constraint while tracking an aggregate.
Choose/skip decisions over items with capacity; tabulate optimal value for subproblems.
Recursive or stack-based depth-first traversal; pre/in/post order.
Two pointers move at different speeds through a linked structure to detect cycles or find midpoints.
DFS through a decision tree, undoing choices on failure to try alternatives.
Sort intervals by start, then sweep merging overlaps.
Place each number at its index by swapping; O(n) sort when values are a known bounded range like 1..n.
Reverse pointers segment by segment without extra space using prev/curr/next bookkeeping.
Level-order traversal using a queue; emit one level at a time.
Iteratively or recursively build all subsets/permutations/combinations by extending prior results.
Binary search on a non-trivial space: rotated arrays, infinite arrays, the answer itself.
Maintain a heap of size k to track the k largest/smallest/most-frequent elements.
Order a DAG so every edge points forward; Kahn's BFS using in-degrees, or DFS post-order.
Explore a graph by levels (BFS) or branches (DFS), tracking visited nodes.
Stack/deque maintained in increasing or decreasing order to answer next-greater/smaller queries.
Maintain a max-heap for the lower half and a min-heap for the upper half of a stream.
Use XOR's self-cancellation property to find unique elements or toggle bits efficiently.
Use a min-heap of k pointers (one per list) to merge k sorted sources in O(N log k).
Tree where each edge is a character; O(L) insert/search/prefix.
Disjoint-set structure with path compression + union by rank for near-O(1) component queries.
Make a locally optimal choice at each step; prove (or trust) it yields a global optimum.