Combinations - Problem
Given two integers n and k, return all possible combinations of k numbers chosen from the range [1, n].
You may return the answer in any order.
A combination is a selection of items without regard to the order of selection.
Input & Output
Example 1 — Basic Case
$
Input:
n = 4, k = 2
›
Output:
[[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
💡 Note:
All possible combinations of 2 numbers from range [1,4]: choose 2 from {1,2,3,4}
Example 2 — Single Element
$
Input:
n = 1, k = 1
›
Output:
[[1]]
💡 Note:
Only one way to choose 1 number from range [1,1]: just [1]
Example 3 — Choose All
$
Input:
n = 3, k = 3
›
Output:
[[1,2,3]]
💡 Note:
Only one way to choose all 3 numbers from range [1,3]: take everything
Constraints
- 1 ≤ n ≤ 20
- 1 ≤ k ≤ n
Visualization
Tap to expand
Understanding the Visualization
1
Input
n=4, k=2 means choose 2 numbers from {1,2,3,4}
2
Process
Generate all possible combinations systematically
3
Output
Return all valid k-sized combinations
Key Takeaway
🎯 Key Insight: Use backtracking to systematically build combinations one element at a time
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code