The Combination Sum interview question asks you to find all unique combinations of numbers from a given set of candidates that sum up to a target value. A crucial rule in this problem is that you can use the same candidate number an unlimited number of times. The resulting list of combinations must not contain duplicate sets (though the sets can contain the same number multiple times).
This is a core Backtracking interview pattern used by companies like Meta, Google, and Amazon. It tests a candidate's ability to explore a state space using recursion. Interviewers look for how you handle the "unlimited use" constraint and how you prevent duplicate combinations in your result list. It also evaluates your understanding of recursion pruning—stopping the search once the current sum exceeds the target.
The problem is solved using Backtracking. You traverse a decision tree where at each step you have two choices:
Candidates: [2, 3, 6, 7], Target: 7
2.2, 2, 2, 2 (Sum 8 > 7, Stop).2, 2, 3 (Sum 7, Success! Add [2, 2, 3] to results).2, 3, 2 (This is the same as [2, 2, 3]. To avoid this, we only consider candidates at or after the current index).7 (Sum 7, Success! Add [7] to results).
Final result: [[2, 2, 3], [7]].[2, 3, 2] and [2, 2, 3] as separate answers. This is usually fixed by passing the current index to the recursive call.Always draw the recursion tree for a small example. It helps you visualize how the index moves forward and how the "unlimited reuse" is implemented by not incrementing the index when you pick a number.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Combination Sum II | Medium | Solve | |
| Permutations | Medium | Solve | |
| Combination Sum III | Medium | Solve | |
| Construct the Lexicographically Largest Valid Sequence | Medium | Solve | |
| Permutations III | Medium | Solve |