You are given a string ‘NUM’ of length ‘N’, representing the digits of a very large number and an integer ‘K’. You can swap any two adjacent digits of ‘NUM’ at most ‘K’ times.
Your task is to find the minimum integer that can be obtained and return it as a string.
Example :‘NUM’ = “5432”, ‘N’ = 4 and ‘K’ = 4.
We can perform the following ‘4’ swaps to obtain the minimum integer from “5432”:

Thus, you should return the string “2453” as the answer.
Note :
1. ‘NUM’ doesn’t have leading zeroes.
2. The resultant minimum integer can have leading zeroes.
The first line of input contains an integer ‘T’ which denotes the number of test cases. Then, the ‘T’ test cases follow.
The first line of each test case contains two integers, ‘N’ and ‘K’, denoting the number of digits in ‘NUM’ and the maximum allowed swaps.
The second line of each test case contains the string ‘NUM’.
Output Format :
For every test case, return the string representing the minimum integer obtained by performing at most ‘K’ swaps.
Note :
You do not need to print anything; it has already been taken care of. Just implement the function.
1 <= T <= 10
1 <= N <= 500
1 <= k <= 10^4
The string ‘NUM’ contains only digits in the range [0, 9].
Time limit: 1 sec
2
5 3
90761
4 5
1324
06971
1234
Test Case 1:
We can perform the following ‘3’ swaps to obtain the minimum integer from “90761”:

Thus, you should return the string “06971” as the answer.
Test Case 2:
We can perform the following swap to obtain the minimum integer from “1324”:

Thus, you should return the string “1234” as the answer.
2
6 12
654321
5 100
14689
123654
14689
Think in a greedily manner i.e. the most significant (leftmost) digit should be the minimum of the first ‘K + 1’ digits (given that ‘K + 1 <= N’)
The idea behind the greedy approach:
We need two levels of loops, the outer loop to traverse the integer ‘NUM’, and the inner (nested) loop to find the smallest leftmost digit among the next ‘K’ digits and swap the digits in between.
Algorithm:
O(N^2), where ‘N’ is the number of digits in ‘NUM’.
We use two nested loops that perform ‘N*(N-1)/2’ operations in the worst-case scenario. Thus, the time complexity is ‘O(N^2)’.
O(1),
Since we are not using any extra space, space complexity is constant.