Largest Permutation
Submissions: 839   Accuracy:

30.44%

  Difficulty: Easy   Marks: 2

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.

Input:
The first line of input contains an integer T denoting the number of test cases. Each test case contains two integers n and k where n denotes the number of elements in the array a[]. Next line contains space separated n elements in the array a[].

Output:
Print space separated n integers which form the largest permutation after at most k swaps.

Constraints:
1<=T<=100
1<=n<=1000
1<=a[i]<=1000
1<=k<=100 0

Example:
Input:

2
5 3
4 5 2 1 3
3 1
2 1 3
Output:
5 4 3 2 1 
3 1 2 

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Shashwat Jain
Author: shashwat jain


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.