Reported August 2026
Pinterestbacktracking

Fixed-Length Combination Sum

Reported by candidates from Pinterest's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Pinterest OA. Under 2s to a working solution.
Founder's read

The Pinterest OA reported in August 2026 hands you a tiny number line, 1 through 9, and asks for every group of exactly k distinct values that adds up to target. Small input, but it's a backtracking question, and the output order matters. If you've seen Combination Sum III, you already know the shape. If you haven't, you've got a day or two to learn one template. And if your head goes blank mid-assessment, StealthCoder runs invisibly on your desktop and gives you a working solution as a safety net.

The problem

Given integers k and target, return every combination of exactly k distinct integers from 1 through 9 whose sum is target.
Each value may be selected at most once.
Values within a combination must be increasing.
Return the combinations in lexicographic order.

Function
fixedLengthCombinationSum(k: int, target: int) → int[][]

Examples
Example 1
k = 3
target = 7
return = [[1,2,4]]
The only three distinct values from 1 through 9 that sum to 7 are 1, 2, and 4.
Example 2
k = 3
target = 9
return = [[1,2,6],[1,3,5],[2,3,4]]
These are all increasing three-value combinations with sum 9.
Example 3
k = 4
target = 1
return = []
The smallest sum of four distinct positive values is greater than 1.

Constraints
1 <= k <= 9.
1 <= target <= 60.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is backtracking with a start index. Pick values in increasing order, so each combination is built once and comes out sorted. Iterate from the start value up to 9, add the number, recurse with start+1, then remove it. Lexicographic order comes free if you loop ascending. Prune hard: stop when the current sum exceeds target, stop when the path already has k values, and skip when there aren't enough numbers left to fill k slots. Common pitfalls are reusing a value by recursing with the same index, forgetting to copy the path before appending it to results, and returning nothing for impossible cases like k=4, target=1 instead of an empty list. With only 9 values, the search is at most 512 subsets, so performance isn't the risk. Correctness is. If you freeze on the recursion, StealthCoder is the hedge during the live OA.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Fixed-Length Combination Sum 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. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Pinterest's OA.

Pinterest reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Fixed-Length Combination Sum FAQ

How hard is the Pinterest Fixed-Length Combination Sum question really?+

Medium at most. The search space is 9 numbers, so there's no performance trap. The difficulty is writing clean backtracking, avoiding duplicates, and copying the path correctly. If you've written a subsets or combinations template before, it's about 15 lines.

What's the core trick?+

Recurse with a start index so values only go upward. That guarantees distinct values, increasing order within a combination, and lexicographic order across results. Add a value, recurse from value+1, then pop it. That's the whole pattern.

What pruning should I add?+

Stop when the path length hits k, and only record if the sum equals target. Break out of the loop once the running sum plus the current number exceeds target, since later numbers are larger. These cuts keep it fast and tidy.

What edge cases break solutions?+

Impossible inputs, like k=4 with target=1, must return an empty list. Also watch for pushing the same array reference into results without copying it, which leaves you with empty or mutated lists at the end.

How do I prepare in 48 hours?+

Write the backtracking template from memory three times: subsets, combinations, then this one with a sum constraint. Trace Example 2 by hand to see the order of output. That covers it. Backtracking questions repeat the same skeleton.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Pinterest.

OA at Pinterest?
Invisible during screen share
Get it