210. All Permutations
MediumBacktracking
Print all permutations of the distinct values in lexicographic order, one per line.
Input format
Line 1: n Line 2: n distinct integers
Output format
n! lines.
Example 1
Input
3 1 2 3
Output
1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1
Example 2
Input
1 9
Output
9
Constraints
1 ≤ n ≤ 7
Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.
Loading the MyLoginn IDE…