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...
Top HyperVerge Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
>
HyperVerge Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app