Basic example
Input
n = 4, k = 2
Output
[[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]
All 2-number combinations from 1..4 in lexicographic order.
Full lesson preview
Generate all k-sized combinations from numbers 1..n using backtracking.
Problem statement
Task
Examples
Input
n = 4, k = 2
Output
[[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]
All 2-number combinations from 1..4 in lexicographic order.
Input format
Output format
Constraints
Samples
Input
n = 1, k = 1
Output
[[1]]
Only one possible combination.