LeetCode Patterns: All 22 Coding Interview Patterns

There are thousands of LeetCode problems and a much smaller number of ways to solve them. A pattern is the reusable half: the data structure, the loop shape and the invariant that make a family of problems collapse into one. Learn the pattern and you stop solving problems one at a time — which is the only strategy that scales, because no amount of memorising covers the specific problem you get asked.

Each hub below is a full page: what the pattern is, when it applies, a Python template, the time and space complexity with the reason behind it, and every problem in this library the pattern covers, grouped by difficulty. Counts are computed from the dataset, so they are what the page actually lists.

Sliding Window116 problems · 12 Easy · 74 Medium · 30 HardCollapse a nested loop over every subarray into a single pass with two indices.Topological Sort32 problems · 0 Easy · 14 Medium · 18 HardOrder a set of tasks so that every dependency comes before the thing that needs it.Monotonic Stack225 problems · 21 Easy · 115 Medium · 89 HardAnswer "what is the next greater element" for every position in one pass.Stack194 problems · 26 Easy · 107 Medium · 61 HardWhen the most recent unresolved thing is the one that matters, use a stack.Union-Find83 problems · 1 Easy · 44 Medium · 38 HardMerge groups and ask whether two things are connected, both in near-constant time.Two Pointers201 problems · 58 Easy · 118 Medium · 25 HardUse the order already in the input to discard half the search space at every step.Binary Search254 problems · 31 Easy · 138 Medium · 85 HardHalve the search space each step — over an array, or over the answer itself.Dynamic Programming481 problems · 12 Easy · 243 Medium · 226 HardDefine a state, write the transition, and stop recomputing the same subproblem.Backtracking105 problems · 3 Easy · 71 Medium · 31 HardBuild candidates one choice at a time and abandon a branch the moment it cannot work.Depth-First Search366 problems · 41 Easy · 214 Medium · 111 HardFollow one path to its end before trying the next — the default way to explore a graph.Breadth-First Search233 problems · 23 Easy · 148 Medium · 62 HardExpand outward level by level, so the first time you arrive is the shortest way.Prefix Sum157 problems · 14 Easy · 102 Medium · 41 HardPrecompute running totals once so any range query becomes a single subtraction.Heap / Priority Queue163 problems · 13 Easy · 87 Medium · 63 HardKeep only the best k elements, or always pull the smallest, in log time.Greedy346 problems · 41 Easy · 234 Medium · 71 HardTake the locally best option every time — when you can prove that never costs you later.Linked List75 problems · 12 Easy · 56 Medium · 7 HardRewire pointers in place, with a dummy head and a saved next to keep it safe.Tree Traversal225 problems · 41 Easy · 142 Medium · 42 HardChoose the order — preorder, inorder, postorder, level — and the problem solves itself.Trie49 problems · 3 Easy · 24 Medium · 22 HardStore a set of words by their shared prefixes so lookups cost the length of the word.Bit Manipulation194 problems · 40 Easy · 96 Medium · 58 HardUse XOR, masks and the low-bit trick to replace whole data structures with an integer.Matrix and Grid216 problems · 32 Easy · 125 Medium · 59 HardTreat a 2-D grid as a graph whose neighbours are the four adjacent cells.Hash Map709 problems · 227 Easy · 372 Medium · 110 HardTrade memory for time: remember what you have seen so the second pass never happens.Sorting401 problems · 80 Easy · 227 Medium · 94 HardSpend O(n log n) once to buy an ordering that makes the rest of the problem trivial.Math and Number Theory485 problems · 121 Easy · 244 Medium · 120 HardFind the closed form, the invariant, or the modular identity — and skip the loop entirely.

Looking for a specific problem? Every pattern hub links straight to it — or start from the full problem list.

Stuck on the one you get asked

Stealth Interview is a desktop app for macOS and Windows. It reads the coding problem off your screen, returns a working solution with a step-by-step explanation and its time and space complexity, and transcribes what the interviewer is saying — while staying invisible to screen sharing.