CoursesBacktracking & Greedy

Constraint Search

Lessons
9
Exercises
58
Minutes
62
  1. 1

    Search Under Constraints

    Constraints checked before recursing kill whole subtrees — and shared boards demand mark, explore, unmark so sibling branches start clean.

    Code orderMultiple choice
    6 exercises
    5 min
  2. 2

    Word Search

    Trace a word through the grid cell by cell: mark, explore all four directions, and restore — or sibling paths inherit a corrupted board.

    Complete codeDebugMultiple choiceTrace
    6 exercises
    6 min
  3. 3

    Restore IP Addresses

    Cut a digit string into exactly four valid segments — and let length bounds kill impossible branches before they spawn.

    Complete codeDebugMultiple choice
    7 exercises
    7 min
  4. 4

    Path with Maximum Gold

    Grid backtracking with a value: DFS from every nonzero start, mark cells so one path never revisits them, and restore every mark so other branches and starts see the full mine.

    Complete codeDebugMultiple choiceTrace
    6 exercises
    7 min
  5. 5

    Matchsticks to Square

    Bucket assignment: every stick must land in one of 4 sides. Fast-fail on impossible totals, sort descending so big sticks fail early, and skip equal-valued buckets to kill symmetric branches.

    Complete codeDebugMultiple choiceTrace
    7 exercises
    7 min
  6. 6

    Beautiful Arrangement

    Position-by-position search with a divisibility constraint — prune illegal numbers before recursing, and count completions instead of collecting them.

    Complete codeMultiple choiceTrace
    6 exercises
    7 min
  7. 7

    Constraint Search CheckpointCheckpoint

    No new concepts — carry the island's constraint moves to unseen problems: k equal-sum buckets, equal-sum halves, dictionary segmentation, and knight paths on a tiny board.

    Code orderMultiple choiceTrace
    6 exercises
    7 min
  8. 8

    Constraint Search ReviewReview

    Mixed recap of the island: prune at the branch vs filter at the leaf, the mark/explore/unmark contract on shared boards, O(1) constraint bookkeeping, global fast-fails, and symmetric-bucket pruning.

    Complete codeMultiple choice
    6 exercises
    6 min
  9. 9

    Boss: N-QueensBoss

    The island's final test: place n queens so none attack. Row-by-row construction plus three O(1) sets — columns, row − col, row + col — replace board rescans with three lookups; the trap is checking columns only.

    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.