All lessons

Backtracking

10 min · Python examples

Try choices, undo when they fail, and search all valid combinations.

PHP · Backtracking0/5 cleared

Enemy 1 of 5

Backtracking builds an answer piece by piece. Make a choice, recurse, then undo (backtrack) if the path doesn't work.

Generating all subsets is the hello-world of backtracking.

You
Cosmic-Ray Alien
Loading editor…
Target output: 8

Stuck? Ask Rena

Your AI tutor that gives assistance.

Asking Rena in lessons is on Ultimate.