dsa · medium
Combinations
Return every combination of k distinct integers chosen from 1..n. Order inside a combination does not matter; [1,2] and [2,1] are the same and should appear once. Order of the combinations themselves does not matter.
Arguments
n— upper bound of the integer range 1..nk— size of each combination
Example
n = 4, k = 2 → [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]].
Constraints
1 <= k <= n <= 20
Examples
Example 1
Input: 4 2 Expected: [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
Example 2
Input: 1 1 Expected: [[1]]