Unique Single-Use Sum Combinations
Updated
Problem statement
Given positive integers in candidates and a positive integer target, return every distinct value combination that sums to target. Each input position may be used at most once. Different positions may contain equal values.
For this exercise, assume each returned combination is in nondecreasing order and the complete result is in lexicographic order. Equal value lists appear once, even when they can be formed from different input positions. Return an empty list if no combination works. Do not change the input.
Function
uniqueCombinations(candidates: int[], target: int) → int[][]Examples
Example 1
candidates = [2,5,2,1,2]target = 5return = [[1,2,2],[5]]The distinct value combinations are [1,2,2] and [5]. The two copies of 2 in the first answer use two separate input positions; choosing a different pair of equal positions does not create a new value combination.
Example 2
candidates = [3,7]target = 6return = []The one available 3 can be used once, so [3,3] is not allowed. Neither available value alone is 6, and choosing both sums to 10.
Example 3
candidates = [4,4,4]target = 8return = [[4,4]]Any two of the three positions containing 4 sum to 8. They all give the same value list [4,4], which appears once.
Constraints
- For this exercise, assume
0 <= candidates.length <= 18. - For this exercise, assume
1 <= candidates[i] <= 30. - For this exercise, assume
1 <= target <= 200.
More LinkedIn Onsite Interview questions
- Explore an Unknown Grid and Find a PathONSITE INTERVIEW · Seen Nov 2026
- Fire Station Response BillONSITE INTERVIEW · Seen Nov 2026
- Roll a Weighted DieONSITE INTERVIEW · Seen Oct 2026
- Longest Binary Subarray With at Most K OnesONSITE INTERVIEW · Seen Oct 2026
- Kth Closest Element in a BSTONSITE INTERVIEW · Seen Oct 2026
- Longest Binary Window with at Most K OnesONSITE INTERVIEW · Seen Oct 2026
- LRU Cache OperationsONSITE INTERVIEW · Seen Oct 2026
- Lexicographically Smallest Course OrderONSITE INTERVIEW · Seen Oct 2026
- K Closest Values in a Binary Search TreeONSITE INTERVIEW · Seen Oct 2026
- Maximum Consecutive Ones in a Circular ArrayONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Bounded Combination Sum with Signed CandidatesConfluent · ONSITE INTERVIEWConfluent interview questions
- Spaceship Equipment LoadoutJane Street · ONSITE INTERVIEWJane Street interview questions
- Insert Addition and Multiplication OperatorsPinterest · ONSITE INTERVIEWPinterest interview questions
- Enumerate Character Paths to a MarkerTesla · ONSITE INTERVIEWTesla interview questions
- Maximum Unique-Character Word SubsetMeta · ONSITE INTERVIEWMeta interview questions
- Subsets IIBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Generate Circular Student ArrangementsAmazon · ONSITE INTERVIEW
- Validate a Simplified Mahjong Winning HandGoogle · ONSITE INTERVIEWGoogle interview questions
- Combination Sum With Unlimited ReuseMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Eight-Direction Word SearchMotive · ONSITE INTERVIEWMotive interview questions