Skip to main content

Coding Interview Patterns

21 patterns · 206 curated problems

13M 2H

Sliding Window

Efficiently process subarrays or substrings of a fixed or variable size.

  • Finding max/min subarray of size k
  • Longest substring without repeating characters
15 problems Study pattern
5E 7M 1H

Two Pointers

Use two indices moving toward each other or in the same direction to solve linear problems.

  • Pair sum in sorted array
  • Removing duplicates in-place
13 problems Study pattern
1E 7M 2H

Binary Search

Halve the search space each step to find an element or boundary in O(log n).

  • Searching in sorted array
  • Finding first/last occurrence
10 problems Study pattern
3E 4M

Prefix Sum

Precompute cumulative sums to answer range queries in O(1).

  • Range sum queries
  • Subarray sum equals k
7 problems Study pattern
6E 6M

Hash Map / Set

Trade space for time using O(1) lookup to find pairs, duplicates, and frequencies.

  • Two sum (find complement)
  • Anagram grouping
12 problems Study pattern
1E 9M

Stack

LIFO structure for matching brackets, evaluating expressions, and monotonic problems.

  • Valid parentheses / bracket matching
  • Next greater element
10 problems Study pattern
9M 1H

Queue / BFS

Level-by-level traversal for shortest paths and layer-based problems.

  • Shortest path in unweighted graph
  • Level-order tree traversal
10 problems Study pattern
7M 2H

Heap / Priority Queue

Efficiently track the k-th largest/smallest element or merge sorted sequences.

  • Kth largest/smallest element
  • Merge k sorted lists
9 problems Study pattern
4E 6M 1H

Linked List

Pointer manipulation for in-place list operations without extra memory.

  • Detecting cycles (Floyd's algorithm)
  • Reversing a linked list
11 problems Study pattern
4E 10M 2H

Trees / DFS

Recursive and iterative depth-first traversal for tree structure problems.

  • Tree height/depth
  • Path sum problems
16 problems Study pattern
9M

Graphs

DFS and BFS on adjacency lists for connectivity, cycles, and path problems.

  • Number of islands
  • Clone graph
9 problems Study pattern
3E 21M 2H

Dynamic Programming

Break problems into overlapping subproblems and build up solutions bottom-up.

  • Fibonacci and climbing stairs
  • Knapsack variants
26 problems Study pattern
7M 1H

Greedy

Make the locally optimal choice at each step to achieve a globally optimal solution.

  • Jump game
  • Gas station
8 problems Study pattern
9M 1H

Backtracking

Explore all possibilities recursively, pruning invalid branches early.

  • Generate all permutations/combinations/subsets
  • N-Queens
10 problems Study pattern
4M 1H

Trie

Prefix tree for efficient string search, autocomplete, and word matching.

  • Implement Trie (insert/search/startsWith)
  • Word search II
5 problems Study pattern
5M 1H

Union Find

Disjoint set union for grouping, connectivity, and cycle detection.

  • Number of connected components
  • Redundant connection (cycle detection)
6 problems Study pattern
1E 4M 1H

Monotonic Stack

Maintain a sorted stack to find next/previous greater or smaller elements in O(n).

  • Largest rectangle in histogram
  • Trapping rain water
6 problems Study pattern
4M

Topological Sort

Linear ordering of vertices in a DAG — essential for dependency problems.

  • Course Schedule (detect cycle)
  • Course Schedule II (ordering)
4 problems Study pattern
6E 2M

Bit Manipulation

Use bitwise operations to solve XOR, subset, and number theory problems.

  • Single number (XOR trick)
  • Number of 1 bits (Hamming weight)
8 problems Study pattern
1E 2M 1H

Intervals

Merge, insert, and count overlapping intervals after sorting by start time.

  • Merge intervals
  • Insert interval
4 problems Study pattern
1E 6M

Matrix

Navigate 2D grids with DFS/BFS, rotation, spiral traversal, and flood fill.

  • Rotate image 90°
  • Spiral matrix traversal
7 problems Study pattern
Cheat Sheet All 21 patterns on one page — templates, when-to-use signals & complexity Print it, pin it, and keep it open during your mock interviews. →
Buy me a coffee