Combination Sum with Reusable Values
Updated
Problem statement
Given an array of distinct positive integers candidates and a positive integer target, return every unique combination whose values sum to target.
- You may select the same candidate any number of times.
- Each combination must be nondecreasing.
- Return the combinations in lexicographic order.
Function
combinationSumReuse(candidates: int[], target: int) → int[][]Examples
Example 1
candidates = [2,3,6,7]target = 7return = [[2,2,3],[7]]The value 2 may be reused, giving [2,2,3]. The single value 7 is the other valid combination.
Example 2
candidates = [2,3,5]target = 8return = [[2,2,2,2],[2,3,3],[3,5]]All three nondecreasing combinations sum to 8 and are listed lexicographically.
Example 3
candidates = [3,4]target = 2return = []Every candidate exceeds target, so no combination is possible.
Constraints
1 <= candidates.length <= 30.1 <= candidates[i] <= 40.- All values in
candidatesare distinct. 1 <= target <= 40.
More Pinterest Phone Screen questions
- Shortest Pin Path Through TopicsPHONE SCREEN · Seen Nov 2026
- Top K Pins with Insert and QueryPHONE SCREEN · Seen Nov 2026
- Pins Violation Log QueriesPHONE SCREEN · Seen Nov 2026
- Sparse Matrix Addition and MultiplicationPHONE SCREEN · Seen Nov 2026
- Minimum Bus Routes to a DestinationPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Delete and Compact a Forest SubtreePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Optimal Account BalancingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Aggregate Matching IPv4 Addresses Across ResponsesPHONE SCREEN · Seen Oct 2026
- Escape Room LeaderboardPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Shortest Way to Form a Target StringPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- All Subsets with a Given SumApple · PHONE SCREENApple interview questions
- Validate a Mahjong Hand PartitionDuolingo · PHONE SCREENDuolingo interview questions
- Combination Sum With Unlimited ReuseMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- All Subsequences with Sum KExpedia · ONSITE INTERVIEWExpedia interview questions
- Count Complete Tic-Tac-Toe GamesDecagon · PHONE SCREEN · ONSITE INTERVIEWDecagon interview questions
- Largest Number Below N from Reusable DigitsByteDance · PHONE SCREENByteDance interview questions
- SubsetsTemu · PHONE SCREENTemu interview questions
- Filter Data with Composable PredicatesCoreWeave · PHONE SCREEN
- PermutationsEPAM · PHONE SCREENEPAM interview questions
- Permutations of Unique CharactersSalesforce · PHONE SCREENSalesforce interview questions