Combination Sum II With Negative Values
Updated
Problem statement
Given an integer array candidates and an integer target, return all distinct combinations whose values sum to target. Candidates may be negative, zero, or positive.
- Each input position may be selected at most once. Equal values from different positions may both be used.
- Selections with the same multiset of values are one combination and must appear only once.
- Write each combination in nondecreasing order. Return rows in lexicographic order: compare the first unequal value; if one row is a prefix of another, put the shorter row first.
- Include the empty combination exactly when
target == 0. Other zero-sum combinations must still be returned.
Return an empty outer array when no combination exists. Candidates cannot be reused indefinitely: this is a finite single-use exercise even when negative values occur.
Function
combinationSumSigned(candidates: int[], target: int) → int[][]Examples
Example 1
candidates = [-1,0,1,1]target = 0return = [[],[-1,0,1],[-1,1],[0]]The empty selection, [-1,0,1], [-1,1], and [0] sum to zero. The two occurrences of 1 do not create duplicate result rows.
Example 2
candidates = [-3,-2,4]target = 1return = [[-3,4]]Only -3 + 4 = 1 works. A negative value cannot be reused, and each selected input position is used once.
Constraints
0 <= candidates.length <= 16-100 <= candidates[i] <= 100-1600 <= target <= 1600- The input guarantees at most
500distinct returned combinations.
More ByteDance Phone Screen questions
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Implement QuicksortPHONE SCREEN · Seen Dec 2026
- Largest Rectangle in HistogramPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Reverse Linked ListPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Count N-Queens PlacementsPHONE SCREEN · Seen Nov 2026
- Matrix EscapePHONE SCREEN · Seen Nov 2026
- Largest Number Below N from Reusable DigitsPHONE SCREEN · Seen Nov 2026
- Log Analyzer: Busiest Service in a Rolling WindowPHONE SCREEN · Seen Nov 2026
- Majority ElementPHONE SCREEN · Seen Nov 2026
- Valid ParenthesesPHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- PermutationsEPAM · PHONE SCREENEPAM interview questions
- String Permutations in Custom Character OrderWex · OA · PHONE SCREEN
- Permutations IILinkedIn · PHONE SCREENLinkedIn interview questions
- Unique String PermutationsAmazon · PHONE SCREEN
- Combination Sum with Single-Use ValuesPinterest · PHONE SCREENPinterest interview questions
- Sorted Subsets of a StringMicrosoft · PHONE SCREENMicrosoft interview questions
- Combination Sum with Unlimited ReuseNVIDIA · PHONE SCREENNVIDIA interview questions
- Generate All String PermutationsBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Sort by Checking PermutationsMercor · PHONE SCREENMercor interview questions
- Generate All Permutations of a NumberFleetx · ONSITE INTERVIEW
ByteDance interview experiences
- ByteDance TikTok USDS SWE Intern Interview: 1 Experience
- ByteDance MLE New Grad Interviews: 1 Experience
- ByteDance Security SRE Intern Phone Screens: 1 Experience
- ByteDance USDS New Grad SWE Phone Screen: 1 Experience
- ByteDance New Grad Data Engineer Video Interviews: 1 Experience
- ByteDance Trust & Safety Research Scientist Intern: 1 Experience