Skip to content
Patterns

42 problem-solving patterns for coding interviews

Most interview problems are one of a few dozen methods in disguise. These are the 42 that the 150 problems use, in 6 groups, in the order they are taught.

Foundations

Remember what you have seen, in a shape that makes the next question take one step.

Search & scan

Move one or two positions across the input so that nothing is looked at more than a few times.

Trees

Let the shape of the data do the work: the branches of a tree, the letters of a trie, the top of a heap.

Graphs

Visit every place you can reach, once each, in the order that suits the question.

Optimization

Find the best answer without trying every possibility: reuse smaller answers, or take the safe choice first.

Math & bits

Work on the cells, the digits or the bits themselves, in a fixed order.