Combination Sum III

Return all combinations of exactly k distinct digits from 1 through 9 whose sum is n. Each digit may be used at most once. Every valid combination must appear…

Return all combinations of exactly k distinct digits from 1 through 9 whose sum is n. Each digit may be used at most once. Every valid combination must appear once; digit order inside a combination and the order of combinations do not matter. Return an empty array when no combination exists.

- 2 <= k <= 9. - 1 <= n <= 60. - Only digits 1 through 9 may be selected, with no repetitions.

Example 1: input k = 3, n = 7; output [[1,2,4]]. These three distinct digits sum to 7. A two-digit sum does not satisfy the exact-size requirement.

Example 2: input k = 3, n = 9; output [[1,2,6],[1,3,5],[2,3,4]]. All three valid digit sets are included once.

Example 3: input k = 2, n = 1; output []. Even the two smallest distinct positive digits already sum to 3.

Category: Recursion. Topic: recursion. Difficulty: Medium. Patterns: backtracking.