You are given a sequence of integers from 1 to n — that is, the set [1, 2, 3, …, n].
If all the permutations of this set are arranged in lexicographic order, your task is to return the k-th permutation in that order.
For example, when n = 3, all permutations in order are:
Given the values of n and k, find and return the k-th string in this sequence.
Input: n = 3, k = 5
Output: "312"
Explanation:
The 5th permutation in the sequence [1,2,3] is "312".
Input: n = 4, k = 15
Output: "3214"
Explanation:
When all permutations of [1,2,3,4] are ordered, the 15th one is "3214".
Input: n = 2, k = 2
Output: "21"
Explanation:
The permutations are ["12", "21"]. The 2nd one is "21".
Accepted:
Submission: