Combinations
Return all combinations of k numbers from 1..n.
Examples
Input: [4,2]
Output: [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
Input: [1,1]
Output: [[1]]
Hints
Use a recursive approach to build combinations incrementally, adding one number at a time while ensuring no duplicates.
Track the current combination and remaining numbers to choose, pruning paths where remaining choices exceed available numbers.
Optimize by passing the current combination and next start index as parameters to avoid unnecessary copying and ensure efficiency.
Related Problems
Combinations
Return all combinations of k numbers from 1..n.