Skip to content
Decoder

Combination Sum III

Medium

Problem

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.

Example 1

Input
k = 3, n = 7
Output
[[1, 2, 4]]

Example 2

Input
k = 3, n = 9
Output
[[1, 2, 6], [1, 3, 5], [2, 3, 4]]

Example 3

Input
k = 4, n = 1
Output
[]

Constraints

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

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.