CoursesBacktracking & Greedy

Combinations

Lessons
9
Exercises
56
Minutes
62
  1. 1

    Order Doesn't Matter

    Combinations are sets, not sequences: the start-index discipline builds each set exactly once — duplicates die by construction, not by dedup.

    Complete codeMultiple choice
    6 exercises
    5 min
  2. 2

    Choose k of n

    Build every size-k selection from 1..n with the start cursor, and abandon any branch that no longer has enough numbers left to fill its empty slots.

    Complete codeDebugMultiple choice
    6 exercises
    6 min
  3. 3

    Combination Sum III

    Two constraints, two prunes: exactly k distinct digits from 1–9 whose sum lands exactly on n — bail on overshoot AND on running out of slots.

    Complete codeDebugMultiple choiceTrace
    6 exercises
    7 min
  4. 4

    Subsets With Duplicates

    Sort first, then skip an equal element only when it would START a sibling branch (i > start) — never when it continues a path. THE dup-skip idiom.

    Complete codeMultiple choiceTrace
    6 exercises
    7 min
  5. 5

    Combination Sum II

    Dup-skip meets a target sum: recurse with i + 1 so each candidate is used once, and skip equal siblings so no combination appears twice. Two different bugs, two different fixes.

    Complete codeDebugMultiple choiceTrace
    6 exercises
    7 min
  6. 6

    Palindrome Partitioning

    Backtracking over CUT positions: at index i, try every prefix s[i..j] as the next piece, and recurse past j only if that prefix is a palindrome — the constraint prunes the tree.

    Complete codeDebugMultiple choiceTrace
    6 exercises
    7 min
  7. 7

    Combinations CheckpointCheckpoint

    No new concepts — transfer the island's moves to unseen problems: counting coin combinations, factoring an integer, balanced binary strings, and splitting a string into distinct pieces.

    Complete codeCode orderMultiple choiceTrace
    6 exercises
    7 min
  8. 8

    Combinations ReviewReview

    Mixed recap of the island: why start indexes kill orderings, i versus i + 1, the dup-skip guard, the two prunes, copy-on-record, and what enumeration must cost.

    DebugFill blankMultiple choice
    6 exercises
    6 min
  9. 9

    Boss: Combination SumBoss

    The island's final test: enumerate every way to hit a target when candidates may be reused. Recurse with i — not i + 1 — and let sorted input break off overshoots.

    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.