Bounded Combination Sum with Signed Candidates
Updated
Problem statement
You are given distinct nonzero integer candidates, an integer target, and a positive maxLength. Candidate values may be positive or negative, and each candidate may be reused.
Return every unique nonempty combination whose sum is target and whose length is at most maxLength. Sort the values in each combination from smallest to largest. Sort the returned combinations lexicographically: compare the first differing value numerically, and put a shorter combination first if it is a prefix of another.
Function
boundedCombinationSum(candidates: int[], target: int, maxLength: int) → int[][]Examples
Example 1
candidates = [2,3,6,7]target = 7maxLength = 4return = [[2,2,3],[7]]Both combinations sum to 7; candidate reuse permits [2,2,3].
Example 2
candidates = [-1,1]target = 0maxLength = 4return = [[-1,-1,1,1],[-1,1]]The explicit length bound keeps signed-candidate reuse finite. The longer combination sorts first lexicographically because its second value is smaller.
Example 3
candidates = [-2,3]target = 1maxLength = 3return = [[-2,3]]One use of each candidate reaches the target within the length limit.
Constraints
1 <= candidates.length <= 8-100 <= candidates[i] <= 100, every value is nonzero, and all values are distinct.-500 <= target <= 5001 <= maxLength <= 8- The number of returned combinations is at most
5000.
More Confluent Onsite Interview questions
- Implement tail -nPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Sudoku Board ValidationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Sudoku Puzzle SolverPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Sequential Phrase Search Across DocumentsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Detect a Silent SensorONSITE INTERVIEW · Seen Sep 2026
- Build an Inverted Document IndexONSITE INTERVIEW · Seen Sep 2026
- Combination Sum with Unlimited ReuseONSITE INTERVIEW · Seen Sep 2026
- Word Search Across DocumentsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Windowed Key-Value MapPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025
- Get Best PriceONSITE INTERVIEW · Seen Apr 2025
Similar questions at other companies
- Generate All Permutations of a NumberFleetx · ONSITE INTERVIEW
- 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
- Partition into Equal-Sum GroupsPalo Alto Networks · ONSITE INTERVIEWPalo Alto Networks interview questions
- PermutationsEPAM · PHONE SCREENEPAM interview questions
- Combination Sum with Single-Use ValuesPinterest · PHONE SCREENPinterest interview questions
- Combination Sum with Unlimited ReuseNVIDIA · PHONE SCREENNVIDIA interview questions
- Sort by Checking PermutationsMercor · PHONE SCREENMercor interview questions