Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

The Target Combinations

Learn
Play
Prove
Problem context and objectives
Mission briefing

Puzzle systems engineer · A game mechanic is behaving incorrectly

Reuse a choice without reordering it: The Target Combinations.

Brute force may pass the demo but fail when the world fills with players.

How you win

  1. 1Recognize when Combination sum matches the clues
  2. 2Keep this true after every move: path is nondecreasing and remaining equals target minus its sum
  3. 3Reach the result within output-sensitive exponential time

Rules and pressure

  • Target cost: output-sensitive exponential time
  • State rule: path is nondecreasing and remaining equals target minus its sum
Lesson 1 of 3

Live algorithm trace

Combination sum

Complete execution
1 of 5
2
candidate
3
6
7
0
7

Begin with the entire target remaining.

1search(start, remaining)
2if remaining is zero: record
3for each candidate from start
4stop when candidate exceeds remaining
5choose and recurse from same index
6undo
remaining = 7path = []
Truth to preserve / Cost target
Truth to preserve

path is nondecreasing and remaining equals target minus its sum

Cost target

output-sensitive exponential time

A branch chooses candidates from a nondecreasing index onward. Reusing the same index permits unlimited copies, while never returning to earlier indices prevents permutation duplicates.

Your call · What should guide every step of this algorithm?

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead