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 = 3
Output:"213"
Explanation:

3rd permutation of [1,2,3].

Input:n = 2, k = 2
Output:21
Explanation:

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 = 1
Output:1234
Explanation:

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

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!