题目描述
Given a permutation of first n natural numbers as an array and an integer k. Print the lexicographically largest permutation after at most k swaps.
Example 1:
Input:
n=5
k=3
arr[] = {4, 5, 2, 1, 3}
Output: 5 4 3 2 1
Explanation: Swap 1^{st} and 2^{nd} elements: 5 4 2 1 3
Swap 3^{rd} and 5^{th} elements: 5 4 3 1 2
Swap 4^{th} and 5^{th} elements: 5 4 3 2 1
Example 2:
Input:
n=3
k=1
arr[] = {2, 1, 3}
Output: 3 1 2
Explanation: Swap 1^{st} and 3^{re} elements: 3 1 2
Your Task:
Since, this is a function problem. You don't need to take any input, as it is already accomplished by the driver code. You just need to complete the function KswapPermutation() that takes array arr, integer n and integer k as parameters and modifies the array arr and does not return anything.
Expected Time Complexity: O(n).
Expected Auxiliary Space: O(n).
Constraints:
2 ≤ n ≤ 10^{6}
1 ≤ k ≤ n
输入格式
见题面
输出格式
见题面