56. Permutation Sequence
HardMath
The set [1, 2, 3, ..., n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order, we get the following sequence for n = 3: "123", "132", "213", "231", "312", "321". Given n and k, return the k-th permutation sequence.
Examples
Input: 4 9
Output: 2314
Explanation: The 9th permutation of [1,2,3,4] in lexicographic order.
Constraints
- 1 <= n <= 9
- 1 <= k <= n!
Loading...
Run checks all cases above. Submit evaluates all test cases.