Fanpilot

Learn the patterns behind coding interview problems.

Most interview problems are variations on a few dozen ideas. Learn to spot them, and you can solve problems you haven't seen before.

Also here: system design labs for an LRU cache and a file system.

How every lesson works

Write the slow solution that obviously works. Find the repeated work that makes it slow. Then remove only that work. Here is one problem, solved with a sliding window. Press Step to watch it run:

Shortest subarray of [2, 3, 1, 2, 4, 3] with a sum of at least 7

  1. 2
  2. 3
  3. 1
  4. 2
  5. 4
  6. 3

Done. The shortest subarray is [4, 3], length 2.

Sum 7Best 2

Both ends of the window only move right, so one pass checks every window that could be the answer: O(n) time. Read why it never misses the answer

How to study

  • Write the slow solution before you read on. Stop after the problem statement and get something that works.
  • Write the fast solution yourself. Once the lesson shows the repeated work, try to remove it before you read how.
  • Solve it again in a few days. Start from a blank page. Recognizing a solution is not the same as writing it.

To check whether you've learned the pattern or only remember one problem, try the transfer exercises.