Combination Sum with Single-Use Values
Reported by candidates from Pinterest's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt on this Pinterest OA, reported in August 2026, is treating duplicates like a post-processing problem. You generate every combination, shove them in a set, and blow up on time or ordering. This is Combination Sum II in a new coat: array of positive ints, each position used once, distinct value combinations only, output sorted. It's a backtracking problem, and the duplicate skip is the whole test. If you freeze mid-assessment, StealthCoder is the invisible safety net that reads the problem on screen and hands you the solution. Know the trick first.
The problem
Given an array of positive integers candidates and a positive integer target, return every distinct combination whose values sum to target. Each array position may be selected at most once. The input may contain duplicate values, but the result must not contain duplicate combinations. Each combination must be nondecreasing, and the result must be in lexicographic order. Function combinationSumSingleUse(candidates: int[], target: int) → int[][] Examples Example 1 candidates = [10,1,2,7,6,1,5] target = 8 return = [[1,1,6],[1,2,5],[1,7],[2,6]] The two input occurrences of 1 may both be used, but identical value combinations appear only once. Example 2 candidates = [2,5,2,1,2] target = 5 return = [[1,2,2],[5]] Although 2 occurs three times, [1,2,2] is returned only once. Example 3 candidates = [4,4,4] target = 8 return = [[4,4]] Any two input positions form the same value combination, so the result contains one row. Constraints 1 <= candidates.length <= 100. 1 <= candidates[i] <= 50. 1 <= target <= 30.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Sort the array first. That gives you nondecreasing combinations and lexicographic output for free. Then backtrack with a start index. At each level, loop i from start, and if i > start and candidates[i] == candidates[i-1], skip it. That one line kills duplicate combinations without a set. Recurse with i+1 since each position is used once. Prune when the running sum exceeds target, and break the loop, since the array is sorted and everything after is bigger too. The common pitfall is writing i > 0 instead of i > start. That wrongly blocks [1,1,6] because the second 1 is legit at a deeper level. Another trap is dedupe via a set of lists, which works but wastes effort. With target at most 30 the recursion depth stays small. If you blank on the skip condition live, StealthCoder is your hedge, but this one is short enough to memorize.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Combination Sum with Single-Use Values cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as combination sum ii. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Pinterest's OA.
Pinterest reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Combination Sum with Single-Use Values FAQ
What's the trick in this Pinterest combination sum problem?+
Sort, then backtrack with a start index and skip a value when i > start and it equals the previous value. That skips duplicate branches at the same depth while still allowing repeated values deeper in the same combination, like [1,1,6].
Why does i > start matter instead of i > 0?+
i > 0 would skip the second 1 even when the first 1 is already in your current path. That drops valid answers like [1,1,6]. i > start only skips duplicates chosen as siblings at the same recursion level.
Do I need to sort the output separately?+
No. If you sort the input and always pick candidates in increasing index order, each combination is nondecreasing and the DFS emits them in lexicographic order. Extra sorting at the end is unnecessary work and a sign the recursion is off.
How hard is this really?+
Medium. It's a known backtracking pattern, and the constraints are small (target up to 30, values up to 50). The difficulty is getting the duplicate skip right, not performance. If you've seen Combination Sum II, it's a rewrite.
How do I prepare in 48 hours?+
Write the sorted backtracking template from memory twice. Test it on [2,5,2,1,2] with target 5 and [4,4,4] with target 8. Then trace why the skip condition uses start. That covers this problem and its usual variants.