Backtracking Cheat Sheet
You build an answer one choice at a time and undo each choice after you try it. That way you try every possibility.
Unlock the full sheet below.
When to use it
- The problem asks for combinations, permutations, or subsets.
- You need every possible answer instead of just one.
- It also works when the problem only asks if an answer exists, like Word Search.
What's on the sheet
The sheet has a code template you can reuse for every Backtracking problem. It's split into four steps so you can see which part changes from problem to problem. It also shows how to spot the pattern, how fast it runs, the mistakes people often make and the variations you'll see in interviews.
How to get it
You can unlock it with a free account by solving 2 of this pattern's problems.
Preview the Two Pointers sample to see a finished sheet first.