← All resources
Resources · Comp coding

Patterns cheatsheet.
Reach for the right tool.

One block per pattern: the signal that triggers it, the template, and the problems that teach it best. Pair it with the LeetCode Patterns catalog for the full problem set. Tick a row once you can reproduce the template from memory.

6Pattern families
20Templates & cues
≤5Min to recall

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

Tech Interview Handbook — Coding cheatsheet — the "narrate before you code" checklist.
NeetCode — Roadmap — patterns in dependency order, each with a template video.
Resources — LeetCode Patterns — 30 patterns, 90 Easy/Medium/Hard problems in our style.

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

Two Sum II — the sorted-array template.
Valid Palindrome — both-ends variant.
Move Zeroes — the slow/fast 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

Longest Substring Without Repeating — the variable-window template.
Minimum Window Substring — shrink-to-minimise.
Maximum Average Subarray I — fixed window.

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

Binary Search — write it once, cleanly.
Koko Eating Bananas — the "search the answer space" 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

Number of Islands — grid BFS/DFS.
Max Depth of Binary Tree — postorder DFS.
Subsets and Combination Sum — the decision-tree 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.

Recognise & template

Daily Temperatures — the next-greater template.
House Robber — the rob-or-skip recurrence.
Longest Common Subsequence — the two-sequence template.
Learn the signal + the template, not the specific problem · then the problem barely matters. All links open in a new tab.