Skip to content

Coding interview patterns

Eighteen patterns cover almost every interview problem. Recognising which one a problem needs is most of the work, so each pattern below comes with the cue in a problem statement that should make you reach for it. They are listed in roadmap order: each builds on the ones before it.

  1. 01Arrays & Hashing

    258 problems

    Trade memory for time with sets, maps and counting.

    Reach for it when: You need to look something up you have already seen, count frequencies, or group by a key.

  2. 02Two Pointers

    65 problems

    Walk inward or in lockstep over a sorted or symmetric sequence.

    Reach for it when: The input is sorted (or can be), or you compare elements from both ends.

    Builds on Arrays & Hashing

  3. 03Sliding Window

    84 problems

    Grow and shrink a contiguous range while keeping an invariant.

    Reach for it when: Longest, shortest or count of a contiguous subarray or substring with a constraint.

    Builds on Two Pointers

  4. 04Stack

    72 problems

    Defer work until a matching or smaller element appears.

    Reach for it when: Matching brackets, nested structure, or the next greater / smaller element.

    Builds on Arrays & Hashing

  5. 05Binary Search

    119 problems

    Halve a monotonic search space, on indices or on the answer.

    Reach for it when: Sorted input, rotated arrays, or "minimum value that works" with a monotonic check.

    Builds on Two Pointers

  6. 06Linked List

    51 problems

    Pointer surgery with dummy heads and fast / slow runners.

    Reach for it when: Reversing, merging, reordering nodes, or detecting a cycle in place.

    Builds on Two Pointers

  7. 07Trees

    134 problems

    Recursive DFS and level-order BFS over hierarchical data.

    Reach for it when: A binary tree or BST: depth, paths, ancestors, or level-by-level processing.

    Builds on Binary Search, Linked List

  8. 08Tries

    38 problems

    Prefix trees for fast word and prefix lookups.

    Reach for it when: Many words with shared prefixes, autocomplete, or wildcard word search.

    Builds on Trees

  9. Always pull the current best element in log time.

    Reach for it when: Top K, K closest, running median, or repeatedly taking the smallest / largest.

    Builds on Trees

  10. 10Backtracking

    58 problems

    Build candidates step by step and undo choices that fail.

    Reach for it when: Generate all subsets, permutations, combinations or board placements.

    Builds on Trees

  11. 11Graphs

    122 problems

    BFS, DFS, union find and topological order over nodes and edges.

    Reach for it when: Grids of cells, connectivity, islands, dependencies or prerequisites.

    Builds on Trees, Backtracking

  12. 12Advanced Graphs

    22 problems

    Shortest paths, spanning trees and ordering with weights.

    Reach for it when: Weighted edges, cheapest / fastest path, or connecting everything at minimum cost.

    Builds on Graphs, Heap / Priority Queue

  13. Overlapping subproblems indexed by a single position.

    Reach for it when: Count ways, min / max over choices at each index, and greedy fails a counterexample.

    Builds on Backtracking

  14. State over two indices: grids, two strings, or item and capacity.

    Reach for it when: Compare two sequences, walk a grid, or choose items under a budget.

    Builds on 1-D Dynamic Programming, Graphs

  15. 15Greedy

    123 problems

    Commit to the locally best choice when it provably stays optimal.

    Reach for it when: A single pass where the best local move never needs to be undone.

    Builds on Arrays & Hashing, 1-D Dynamic Programming

  16. 16Intervals

    17 problems

    Sort by start or end, then merge or sweep.

    Reach for it when: Ranges with starts and ends: overlaps, merging, meeting rooms.

    Builds on Arrays & Hashing, Heap / Priority Queue

  17. 17Math & Geometry

    217 problems

    Matrix manipulation, number tricks and coordinate reasoning.

    Reach for it when: Rotate or spiral a matrix, digit manipulation, or points on a plane.

    Builds on Arrays & Hashing

  18. 18Bit Manipulation

    55 problems

    XOR, masks and shifts on the binary representation.

    Reach for it when: Find the odd one out, count bits, or arithmetic without operators.

    Builds on Arrays & Hashing