Permutation Sequence
The set [1, 2, 3, ..., n] contains exactly n! unique permutations. When all permutations are listed in lexicographic order, they form a sequence ordered from smallest to largest.
Given two integers n and k, return the kth permutation sequence of the numbers from 1 to n, where k is 1-indexed.
Return the permutation as a string.
Example 1
Input
n = 3, k = 3Output
"213"The permutations of [1, 2, 3] in order are "123", "132", "213", so the 3rd permutation is "213".
Example 2
Input
n = 4, k = 9Output
"2314"The 9th permutation of [1, 2, 3, 4] in lexicographic order is "2314".
Constraints
- 1 <= n <= 9
- 1 <= k <= n!