Sign in to track progress, unlock prep layers, and browse your pipeline.Sign in
Return all combinations that sum to target
Return all combinations that sum to target
Given an array of distinct positive integers candidates and an integer target, return all unique combinations of candidates where the chosen numbers sum to target.
Rules:
- You may use each candidate an unlimited number of times.
- Two combinations are considered the same if they contain the same multiset of numbers (order does not matter).
- Return the combinations in any order.
Example:
candidates = [2,3,6,7],target = 7- Valid output:
[[2,2,3],[7]]
Constraints:
1 <= candidates.length <= 301 <= candidates[i] <= 2001 <= target <= 500
AI interview prep
Core dilemma
Exploring the combinatorial space of candidate numbers to find all valid combinations that sum to a target, while ensuring uniqueness and handling unlimited usage of each candidate.
Mid-level signals3
Senior signals3
Red flags3
2 tradeoffs and 2 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Return all combinations that sum to target
Return all combinations that sum to target
Given an array of distinct positive integers candidates and an integer target, return all unique combinations of candidates where the chosen numbers sum to target.
Rules:
- You may use each candidate an unlimited number of times.
- Two combinations are considered the same if they contain the same multiset of numbers (order does not matter).
- Return the combinations in any order.
Example:
candidates = [2,3,6,7],target = 7- Valid output:
[[2,2,3],[7]]
Constraints:
1 <= candidates.length <= 301 <= candidates[i] <= 2001 <= target <= 500