Read a positive natural number n. Generate and print, in lexicographic
order, all permutations of the set {1, 2, ..., n}.
Read a positive natural number n. Generate and print, in lexicographic
order, all permutations of the set {1, 2, ..., n}.
The program reads from standard input a single natural number, `n`. - `1 <= n <= 7`
The program prints to standard output all permutations of `{1, 2, ..., n}`, one per line. On each line, the values are separated by spaces with no trailing space. Permutations must be printed in lexicographic order (the first element has priority; ties are broken by comparing the second element, and so on).
3
1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1
Use the Get Hint button in the action bar to reveal a guided hint.
No comments yet. Be the first to start the discussion!
3
1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1
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.