Combination Sum
Given an array of distinct integers candidates and an integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target.
You may use the same number from candidates an unlimited number of times.
The combinations can be returned in any order.
Two combinations are considered different if the frequency of at least one chosen number is different.
Example 1
Input
n = 3 candidates = [2, 3, 6] target = 7
Output
2 2 3
Explanation
The only combination that sums to 7 is:
2 + 2 + 3 = 7
The number 2 can be used more than once.
Example 2
Input
n = 4 candidates = [2, 3, 6, 7] target = 7
Output
2 2 3 7
Explanation
There are two valid combinations:
2 + 2 + 3 = 7
7 = 7
Constraints
Hints:
Hint 1
Use backtracking to build a combination one number at a time.
Hint 2
Because a candidate can be used multiple times, after choosing a candidate, continue the recursive call from the same index.
Author & Technical Reviewer
Technically reviewed by: ExamAdda Technical Review Team
Technical Reviewers, ExamAdda
Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.
Published
Aug 20, 2026
Last updated
Aug 21, 2026
Content Verification Methodology
Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.
Expected Output