All cheat sheets
🧩

DSA Patterns

Pattern cheatsheet — recognize the problem shape faster.

Core Patterns

Two pointersSorted arrays, pairs, reverse, containers — O(n) scans.
Sliding windowSubarrays/substrings with constraint (max sum, unique chars).
Hash mapFrequency, complement (Two Sum), first unique, anagrams.
Binary searchSorted search, answer-space search (min capacity, etc.).

Trees & Graphs

BFSLevel order, shortest path in unweighted graphs.
DFSPath existence, components, topo prep, backtracking trees.
Topo sortDAG ordering — Kahn's (BFS) or DFS finish times.
Union-FindConnected components, cycle detection in undirected graphs.

DP Triggers

Optimal substructureSolution builds from smaller subproblems.
Overlapping subsSame subproblems repeat → memo / tabulation.
Classic DPsKnapsack, LCS/LIS, coin change, grid paths, house robber.
State designDefine dp[i] / dp[i][j] meaning first — then transitions.