K-th Permutation Sequence of First N Natural Numbers
Determine the K-th permutation from a sequence of the first N natural numbers.
Input:
Integer T indicating the number of test cases followed by 'T' test cases. Each test case contains two space-separated integers: N and K.
Output:
An array representing the K-th permutation of the first N natural numbers for each test case.
Example:
Input:
2 3 3
Output:
[2, 1, 3]
Explanation:
The permutations for N = 3 are {(1,2,3), (1,3,2), (2,1,3), (2,3,1), (3,1,2), (3,2,1)}. The 3rd permutation is [2, 1, 3].
Constraints:
1 ≤ T ≤ 10
1 ≤ N ≤ 5 * 103
1 ≤ K ≤ min(N!, 5 * 103)
Time limit: 1 sec
Note:
No need for printing in solution; implement the function to return results.

AnswerBot
1y
The task is to find the Kth permutation of the sequence of first N natural numbers.
Generate all possible permutations of the sequence of first N natural numbers
Sort the permutations in lexicographical...read more
Help your peers!
Add answer anonymously...
>
HyperVerge Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

