1How to use this sheet
0/3▶A cheatsheet is a recognition tool, not a solutions list. For each pattern, learn the signal that triggers it and the template — then the specific problem barely matters.
The drill
2Two Pointers
0/3▶Signal: a sorted array, or a question about pairs / palindromes / both ends. Turns many O(n²) brute forces into O(n), O(1) space.
Recognise & template
3Sliding Window
0/3▶Signal: contiguous subarray/substring with a constraint ("longest/shortest/at most k"). Grow right, shrink left when the constraint breaks.
Recognise & template
4Binary Search
0/3▶Signal: sorted input, or you can phrase the answer as "smallest/largest x for which P(x) is true" (monotonic predicate). O(log n).
Recognise & template
5BFS / DFS & Backtracking
0/3▶Signal: trees, graphs, grids, or "generate all combinations/permutations". BFS for shortest unweighted path; DFS for reachability/paths; backtracking to enumerate with pruning.
Recognise & template
6Heaps, Stacks & DP
0/4▶The remaining high-value templates. Reach for a heap on "top-k / kth / merge k"; a monotonic stack on "next greater/smaller"; and DP when choices have overlapping subproblems.