Code RoomDigit combinations with sum
MediumPrep Room Coding #355

Digit combinations with sum

CodingAlgorithms & data structuresMid–Senior~20 min

Find all distinct combinations of exactly k different digits from 1 to 9 that sum to n. Each digit may be used at most once and combinations are unordered. Return the list of combinations, each as an ascending list of digits, with the overall list sorted ascending. 1 <= k <= 9 and 1 <= n <= 60.

Implement
combination_sum_iii(k: int, n: int) → list[list[int]]
Examples
in[3,7]out[[1,2,4]]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 20 min
InputExpectedGot
[3,7][[1,2,4]]not run yetsample