


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, where N is the size of the array and K is an integer such that the difference between the maximum and minimum element in the remaining array is less than or equal to K.
The second line of each test case contains N space-separated integers, denoting the array elements.
For every test case, print a single line containing a single integer denoting the minimum number of elements that should be removed from the array, such that that the difference between the maximum and minimum element in the remaining array is less than or equal to K.
The output of each test case will be printed in a separate line.
You do not need to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N <= 10 ^ 5
-10 ^ 9 <= ARR[i] <= 10 ^ 9
Time limit: 1 sec
We will first sort the given array. Then we will start traversing the array using two variables, say ‘i’ and ‘j,’ using a nested loop, where j will be used to fix the maximum element, and i will be used to fix the minimum element and check if arr[j] - arr[i] <= K.
We will first sort the given array. Now, observe that what is the maximum number from which the first element(arr[0]) can be subtracted such that their difference is less than or equal to K. This number is arr[0] + K. Now, we’ll search for this number in the array or the number which is smaller than this number in the given array using binary search.