Free reference library

Coding Interview Pattern Guides

Learn the most reusable coding interview patterns with worked examples, templates, common mistakes, and practice problems. Every guide is free and self-contained.

Pattern guide library

Sliding Window

Maintain a contiguous range without recomputing from scratch. Learn when to expand, shrink, and avoid sum-based windows with negative values.

  • Fixed and variable windows
  • Window state and invariants
  • Expand and shrink templates

Two Pointers

Replace repeated scans with boundaries that move for a reason. Compare opposite-end, same-direction, fast-slow, and read-write pointer models.

  • Pointer placement
  • Movement invariants
  • Sorted and in-place problems

Prefix Sum

Precompute cumulative state to turn range totals and subarray relationships into direct lookups with prefix sums, hash maps, and difference arrays.

  • Range queries
  • Prefix sum plus hash map
  • Difference arrays

Binary Search

Search sorted data and monotonic decision spaces with explicit boundaries. Learn exact search, first and last true, and rotated-array variations.

  • Boundary definitions
  • First and last occurrence
  • Rotated arrays

Hash Maps

Trade repeated lookups for stored information. Learn frequency maps, complements, grouping, visited state, and when a set is enough.

  • Frequency counting
  • One-pass lookups
  • Sets versus maps

Depth-First Search

Explore one branch before returning. Compare recursive and iterative traversal, tree return values, visited state, components, and cycle handling.

  • Trees and graphs
  • Visited state
  • Recursive return values

Breadth-First Search

Process a graph frontier in distance layers. Learn queue mechanics, seen-on-enqueue, shortest paths, multi-source search, and state-space modeling.

  • Distance layers
  • Shortest unweighted paths
  • Multi-source BFS

Stacks

Keep unresolved work in last-in, first-out order. Apply stacks to nesting, monotonic scans, expressions, and simulations.

  • Matching and nesting
  • Monotonic stacks
  • Expression evaluation

Linked Lists

Change references without losing the structure. Learn reversal, dummy nodes, fast-slow pointers, cycle detection, and merging.

  • Reference-safe reversal
  • Dummy nodes
  • Fast and slow pointers

Heaps and Priority Queues

Maintain the next best candidate as data changes. Learn min and max heaps, bounded top-k structures, k-way merge, and streams.

  • Min heap versus max heap
  • Top-k problems
  • K-way merge

Greedy Algorithms

Commit to a local choice only when it preserves the best global result. Learn recognition, correctness arguments, and failure cases.

  • Greedy-choice property
  • Correctness arguments
  • Counterexamples

Intervals

Sort ranges so overlap decisions become local. Learn merging, insertion, scheduling, room counts, and endpoint ties.

  • Merge and insert
  • Scheduling
  • Endpoint sweeps

Backtracking

Explore a decision tree while restoring shared state between choices. Learn subsets, permutations, combinations, pruning, and constraint search.

  • Choose, recurse, undo
  • Choice boundaries
  • Pruning

Tries

Store strings by shared prefixes. Learn trie nodes, insertion, exact and prefix search, autocomplete, and trie-backed board search.

  • Prefix-tree structure
  • Insert and search
  • Trie plus DFS

Union Find

Track changing connectivity without retraversing the graph. Learn parent links, path compression, union by size, and cycle detection.

  • Find and union
  • Path compression
  • Dynamic connectivity

Dynamic Programming

Define what one state answers, derive its recurrence, and evaluate dependencies in order. Learn memoization, tabulation, and major DP families.

  • State and recurrence
  • Memoization and tabulation
  • DP families

Want an ordered path instead?

Pattern Guides are references. The Interview Course sequences the concepts, examples, and problems so each skill builds on the previous one.

Explore the Interview Course