Combination Sum with Unlimited Reuse
Updated
Problem statement
Given an integer array candidates with distinct positive values and a nonnegative integer target, return every combination of candidate values whose sum is exactly target. Each candidate value may be reused any number of times.
Combination rules
- A combination is determined by how many times each candidate value is selected. Different arrangements of the same selected values are one combination.
- Represent each combination as a nondecreasing integer array. Return each distinct combination exactly once.
- The input candidates may be in any order. Leave the supplied array unchanged.
- If
target = 0, return[[]]: the one empty combination. - If no combination reaches a positive target, return
[].
Result order
Order the returned rows in decreasing numeric lexicographic order. Compare integer values from left to right; at the first unequal position, the row with the larger integer comes first. If one row is a prefix of the other, place the longer row first.
For example, [7] comes before [2,2,3], and [1,3] comes before [1,1,2]. Compare integers rather than their decimal strings.
Interview context
Candidates are distinct and may be reused without limit, as in the example candidates = [2,3,6,7], target = 7, output = [[7],[2,2,3]]. Recursion or DFS works well.
Function
combinationSum(candidates: int[], target: int) → List<List<Integer>>Examples
Example 1
candidates = [2,3,6,7]target = 7return = [[7],[2,2,3]]The combinations are [7] and [2,2,3]. Both sum to 7, and the row beginning with 7 comes first in decreasing numeric lexicographic order.
Example 2
candidates = [2]target = 1return = []Every selected value is at least 2, so no combination can sum to 1.
Example 3
candidates = [1,2]target = 0return = [[]]Selecting no values gives the empty combination, whose sum is 0. Positive candidates cannot form any other zero-sum combination.
Constraints
0 <= candidates.length <= 6.- Every candidate value is a distinct integer in
[1,30]. 0 <= target <= 20.- The candidates may be unsorted. Do not modify the supplied array.
More NVIDIA Phone Screen questions
- Network Layer Execution OrderPHONE SCREEN · Seen Nov 2026
- Paged KV Cache AccessPHONE SCREEN · Seen Nov 2026
- Sliding Window Attention over a KV CachePHONE SCREEN · Seen Nov 2026
- Summarize Server Healthcheck LogsPHONE SCREEN · Seen Oct 2026
- Hash Partition OffsetsPHONE SCREEN · Seen Oct 2026
- Filter Paginated Medical RecordsPHONE SCREEN · Seen Oct 2026
- Least Frequently Used CachePHONE SCREEN · Seen Oct 2026
- Parallel String Counts with a Custom Hash TablePHONE SCREEN · Seen Oct 2026
- Simulate a Reference-Counted Smart PointerPHONE SCREEN · Seen Aug 2026
- Streaming Top-K Frequent ElementsPHONE SCREEN · Seen Aug 2026
Similar questions at other companies
- PermutationsEPAM · PHONE SCREENEPAM interview questions
- Combination Sum with Single-Use ValuesPinterest · PHONE SCREENPinterest interview questions
- Sort by Checking PermutationsMercor · PHONE SCREENMercor interview questions
- Generate All Permutations of a NumberFleetx · ONSITE INTERVIEW
- Bounded Combination Sum with Signed CandidatesConfluent · ONSITE INTERVIEWConfluent interview questions
- Enumerate Character Paths to a MarkerTesla · ONSITE INTERVIEWTesla interview questions
- Subsets IIBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Generate Circular Student ArrangementsAmazon · ONSITE INTERVIEW
- Enumerate Compatible Meeting SubsetsExpedia · ONSITE INTERVIEWExpedia interview questions
- Enumerate Valid Clock TimesMicrosoft · OAMicrosoft interview questions