Question bankPricingSign in

Combination Sum

BacktrackingMedium1:30

Given an array of distinct positive integers (candidates) and a target integer, explain how you would find all unique combinations of candidates that sum to the target. Each candidate may be used an unlimited number of times.

For example, given candidates [2, 3, 6, 7] and target 7, the valid combinations are [2, 2, 3] and [7].

Describe your approach, explain how you avoid generating duplicate combinations, and analyze the time and space complexity.

How to approach it

  • Hint 1

    At each step, you choose a candidate to add. How do you ensure you do not produce the same combination in a different order?

  • Hint 2

    Only consider candidates at or after the current index -- never go backwards. This prevents duplicates like [2,3,2] and [3,2,2].

  • Hint 3

    What is your base case? Think about when the remaining target reaches zero versus when it goes negative.

Ready to answer it out loud?

Record your answer in 1:30 and Preptile scores it 1–10 with specifics — what landed, what you skipped, and what to say next time.

Practising needs an invite code. Join the waitlist and we’ll send you one.