algorythms
Subsets / Combinations
LC #77Medium

Combinations

Subsets / Combinations
AmazonGoogleMeta

Problem

Return all combinations of k numbers chosen from range [1, n].

backtracking

Constraints

  • 1 ≤ n ≤ 20
  • 1 ≤ k ≤ n

Example

Inputn = 4, k = 2
Output[[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
Why

C(4,2) = 6 combinations. Choose 2 from [1,2,3,4]

Hints — reveal one at a time