← Whiteboard questions

Pattern

Backtracking

Use backtracking when you must list every sequence of choices that meets a rule. Pick a choice, go deeper, then undo it and try the next. Cut a branch as soon as it cannot work. The cost grows fast, often as O(2^n) or O(n!), so pruning matters.

Backtracking interview questions and solutions