Problem Description
You are given an integer A which represents the length of a permutation.
A permutation is an array of length A where all the elements occur exactly once and in any order.
For example, [3, 4, 1, 2], [1, 2, 3] are examples of valid permutations while [1, 2, 2], [2] are not.
You are also given an integer B.
If all the permutation of length A are sorted lexicographically, return the Bth permutation.
Problem Constraints
Input Format
Output Format
Example Input
A = 3
B = 3
Input 2:
A = 1
B = 1
Example Output
[2, 1, 3]
Output 2:
[1]
Example Explanation
All the permutations of length 3 sorted in lexicographical order are: [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]. Therefore, the third permutation is [2, 1, 3].
Explanation 2:
There is only one possible permutation -> [1].
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a question? Checkout Sample Codes for more details.