Skip to content

Backtracking

Backtracking is exploring a maze: at every junction you pick a path, go as deep as possible, and if it is a dead end you step back and try the next path. It systematically generates every subset, permutation or arrangement while pruning impossible branches early.

After this topic: You can draw the decision tree for a problem and write the choose → explore → un-choose loop.

Do these first: Trees

0 of 9 solved0%

Step 0 · New to this idea? Warm up first

Recursion Basics

Solve a problem with a smaller copy of itself: base case, call stack and why recursion can repeat work.

Step 1 · Read the lesson

Backtracking

Build answers one choice at a time; undo the choice and try the next.

Step 2 · Solve the problems in order

Try each one for about 20 minutes first. Problems with a Run code tab are checked right here. If you are stuck, open Nudge, think again, then Idea. Go skeleton only gives the function shape, and Reference solution is for comparing after you have tried. Tick the box when you could solve it again without help.

  1. 1.Subsets Medium
  2. 4.Subsets II Medium
  3. 6.Word Search Medium
  4. 9.N-Queens Hard

Step 3 · What this unlocks