Description
Return the k-th permutation (1-indexed) of [1, 2, ..., n] in lexicographic order, as a list.
Examples
Input:
n = 3, k = 1Output:
[1,2,3]Explanation:
The first permutation of [1,2,3] in lex order is [1,2,3].
Input:
n = 3, k = 4Output:
[2,3,1]Explanation:
Lex order is 123, 132, 213, 231, 312, 321; the 4th permutation is [2,3,1].
Input:
n = 4, k = 24Output:
[4,3,2,1]Explanation:
With n = 4 there are 24 permutations and the 24th in lex order is the reversed sequence [4,3,2,1].
Constraints
- •
1 ≤ n ≤ 10 - •
1 ≤ k ≤ n!