Subsets / Combinations
LC #77Medium
Combinations
Subsets / Combinations
AmazonGoogleMetaProblem
Return all combinations of k numbers chosen from range [1, n].
backtracking
Constraints
- ›1 ≤ n ≤ 20
- ›1 ≤ k ≤ n
Example
Input
n = 4, k = 2Output
[[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]