Description
Given n and k, return the kth permutation sequence of numbers 1 to n. Permutations are listed in lexicographic order.
Examples
Input:
n = 3, k = 3Output:
"213"Explanation:
3rd permutation of [1,2,3].
Input:
n = 2, k = 2Output:
21Explanation:
For n=2, there are only 2 permutations of [1,2]: "12" (1st) and "21" (2nd). The 2nd permutation is "21".
Input:
n = 4, k = 1Output:
1234Explanation:
The 1st permutation of any sequence [1,2,...,n] is always the numbers in ascending order. For n=4, this is "1234".
Constraints
- •
1 ≤ n ≤ 9