


Let us consider 'K' is 3, an element at index 4 in the sorted array, can be at indexes 1, 2, 3, 4, 5, 6, 7 in the given array, because the absolute difference of all these indices with 4 is at most 3.
The first line of the input contains an integer T denoting the number of test cases.
The first line of each test case contains two space-separated integers N and K, the number of elements in the array and K as specified in the problem statement.
The second line of each test contains N space-separated integers.
The only line of output of each test case should contain N space-separated integers denoting the sorted array.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 100
1 <= K < N <= 5000
1 <= ARR[i] <= 10^9
Time Limit: 1 sec
We will use the Insertion sort to sort the elements efficiently. Insertion sort is a simple sorting algorithm that works similar to the way you sort playing cards in your hands, where we do the following steps.
To sort arrays efficiently, one of the best methods is to use the Heap Data Structure.
We could also use a Balanced Binary Search Tree instead of Heap to store elements as the insert and delete operations on Balanced BST also take O(Logk) time. Hence we can see that a Balanced BST-based method will also take O(N log K) time, but the Heap-based method seems to be more efficient as the minimum element will always be at the root. Also, Heap doesn’t need extra space for left and right pointers. So we will use the Heap Method because of its above-given advantages over the Balanced Binary Search Tree.