Browse Curriculum
FAANGPrep Sprint
Medium
Combination Sum
Find all unique combinations that add up to a target sum (unlimited use of candidates).
10 min read
Solve on LeetCodeProblem 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:
- Include the current candidate number again (and stay at same index
i). - 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
Visualize the decision making. Notice how we can branch 'left' multiple times (reusing same number) until it exceeds target.
Try clicking 'Randomize' to see how the tree changes with different targets and candidates.
ON THIS PAGE
- Problem Understanding
- Algorithm Strategy
- Interactive Visualization
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.
