Read two positive natural numbers n and k (k <= n). Generate and
print, in lexicographic order, all subsets of exactly k elements of
the set {1, 2, ..., n}.
Read two positive natural numbers n and k (k <= n). Generate and
print, in lexicographic order, all subsets of exactly k elements of
the set {1, 2, ..., n}.
The program reads from standard input two natural numbers, `n` and `k`, separated by a space. - `1 <= k <= n <= 8`
The program prints all combinations, one per line. On each line the elements are written in strictly ascending order, separated by spaces, with no trailing space. Combinations must be printed in lexicographic order.
4 2
1 2 1 3 1 4 2 3 2 4 3 4
Use the Get Hint button in the action bar to reveal a guided hint.
No comments yet. Be the first to start the discussion!
4 2
1 2 1 3 1 4 2 3 2 4 3 4
Community solutions unlock after you submit a passing solution. Don't peek.
Create a free account to write code, submit solutions, and track your progress.