Backtracking
Medium

Combination Sum

Find all unique combinations that add up to a target sum (unlimited use of candidates).
Problem Understanding

Given an array of distinct integers candidates and a target, return a list of all unique combinations where the chosen numbers sum to target.

Key Rule: The same number may be chosen from candidates an unlimited number of times.

Algorithm Strategy

This is a classic backtracking problem. At each step, we have choices:

  1. Include the current candidate number again (and stay at same index i).
  2. Skip the current candidate and move to the next (i + 1).

Pruning:

  • If currentSum > target, stop (backtrack).
  • If currentSum == target, add to result.
Interactive Visualization
Step 1 / 1

Visualization coming soon...

Initializing...

1x
See the Logic in Motion
Stop memorizing code. Unlock the full interactive visualizer to master the logic step-by-step.
Unlock VisualizerPREMIUM FEATURE

Stop Guessing, Start Mastering.

Build the FAANG intuition. Master this pattern with optimized implementations, visual dry runs, and our curated collection of high-yield problems.

Start Your Premium Prep