CoursesBacktracking & Greedy

Backtracking Foundations

Lessons
9
Exercises
57
Minutes
61
  1. 1

    Choose, Explore, Unchoose

    Backtracking walks a decision tree: commit to a branch, explore it fully, then undo — the current path lives on a stack.

    Code orderMultiple choice
    6 exercises
    5 min
  2. 2

    Letter Case Permutation

    Two branches per letter, one per digit — walk the case tree over a shared char array and record a string at every leaf.

    Complete codeDebugMultiple choiceTrace
    6 exercises
    6 min
  3. 3

    Sum of All Subset XOR Totals

    Include or exclude each element — 2^n leaves, one subset per leaf, XOR along the path and sum across the leaves.

    Complete codeMultiple choiceTrace
    7 exercises
    7 min
  4. 4

    Letter Combinations of a Phone Number

    Multi-way branching: each digit opens one level of the tree, and each of its letters is one branch — depth equals the number of digits.

    Complete codeMultiple choiceTrace
    6 exercises
    6 min
  5. 5

    Permutations

    Order matters: every unused element branches at every level, tracked by used[] flags — and every mark must be undone on the way back.

    Complete codeDebugMultiple choiceTrace
    6 exercises
    7 min
  6. 6

    Generate Parentheses

    Constrained branching: add '(' while open < n and ')' while close < open — invalid prefixes are never built, so no filtering is needed at the leaves.

    Complete codeDebugMultiple choiceTrace
    6 exercises
    7 min
  7. 7

    Backtracking CheckpointCheckpoint

    No new concepts — transfer the island's branching moves to unseen problems: choose-k LED selections, adjacency-constrained strings, and digit chains where pruning collapses the whole tree.

    Code orderMultiple choiceTrace
    6 exercises
    7 min
  8. 8

    Backtracking ReviewReview

    Mixed recap of the island: the choose/explore/unchoose contract, include/exclude vs used[] branching, why pruning beats filtering, copy-on-record, stack depth vs tree size, and 2^n vs n!.

    Complete codeMultiple choice
    6 exercises
    6 min
  9. 9

    Boss: SubsetsBoss

    The island's final test: enumerate the power set. Every element is one independent in/out decision — 2^n subsets including [] — and the boss's trap is recording a reference to the mutable path instead of a copy.

    Complete codeDebugCode orderMultiple choiceTrace
    8 exercises
    10 min
AlgoFox Pro

Backtracking & Greedy is part of AlgoFox Pro

You can read the whole course outline here. The exercises are in the app, along with your streak, your mistake review, and the progress that carries across your devices.

Pro starts with a 3 day free trial. The app store decides who is eligible for an introductory offer, and a lapsed subscription does not get another one.

Download AlgoFox on the App StoreGet AlgoFox on Google Play

Already subscribed in the app? Sign in with the same account and Pro works here too. Quick Play and Battle are free on the web, and so is the first course in every subject.