Fanpilot

LeetCode patterns

2 min read

A 32-chapter guide to the techniques behind most interview problems, and to telling which one a problem needs. It links 125 practice problems. It doesn't cover every problem, and it doesn't claim to.

A pattern is more than a data structure. A heap is a tool; "only the best k candidates can affect the answer" is the reason to reach for one. Each chapter teaches that reason.

Where to start

New here? Read these three chapters first:

Then pick your next topic from the suggested order, which shows which chapters build on which.

Learn first, then test yourself

  • When you're learning, use worked examples and hints freely. Then close them and rebuild the solution from a blank page.
  • When you're testing yourself, pick a problem without looking at its topic, and solve it without help. Keep track of the two kinds of results separately.
  • Come back to old problems after a few days, and also try a variation. Remembering one solution and choosing the right approach for a new problem are different skills.

The transfer exercises change familiar problems in ways that break the usual method. The hints and answers are on a separate page.

The chapters

Combine several ideas

The LRU cache and file system labs each combine several techniques in one design. Try them once single patterns feel comfortable.

Prefer paper? The PDF edition is the original guide. The website has grown beyond it.