Skip to content

Combination Sum III

MediumBacktracking
Decode it first. Clues, constraints, pattern and plan before any code.

Find every combination of exactly k different numbers chosen from 1 to 9 that add up to n. Each number can be used at most once. Return the combinations in any order, with no combination listed twice.

k = 3, n = 7  →  [[1, 2, 4]]
k = 3, n = 9  →  [[1, 2, 6], [1, 3, 5], [2, 3, 4]]
k = 4, n = 1  →  []

Constraints

  • 2 <= k <= 9
  • 1 <= n <= 60