Problem
Input format
The program reads from standard input a single natural number, `n`. - `1 <= n <= 7`
Output format
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).
Example
3
1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1
Stuck?
Use the Get Hint button in the action bar to reveal a guided hint.
💬 Discussion
Loading...No comments yet. Be the first to start the discussion!
Sample cases (from the problem)
Sample Case 1
3
1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1
Solve it your way first
Community solutions unlock after you submit a passing solution. Don't peek.
Ready to solve this challenge?
Create a free account to write code, submit solutions, and track your progress.