Backtracking Problems for Coding Interviews

Backtracking builds a solution step by step and undoes a choice when it cannot lead to an answer. It is the tool for permutations, combinations, subsets, board puzzles and constraint problems, where you must explore many possibilities.

The template is choose, explore, un-choose. The skill is pruning: stop early when a partial solution already breaks a rule, and avoid repeated work by sorting or skipping duplicates. Practise estimating the size of the search space.

Coding problems

Related

Frequently asked questions

How do I get good at backtracking problems?

Solve a few problems of each difficulty, name the pattern after you solve each one, and revisit the ones you needed hints for a week later. The list on this page is ordered so you can start with the basic ones.

Can I run backtracking problems online here?

Yes. Every problem opens in an editor that runs your code against test cases in Java, Python, C++, Go, JavaScript and six more languages, with no setup.