


The first line contains a single integer ‘T’ representing the number of test cases. The 'T' test cases follow.
The first line of each test case will contain two integers ‘N’ and ‘K’ where ‘N’ is the number of elements in the array, and the integer ‘K’ is described as above.
The second line of each test case will contain ‘N’ space-separated integers denoting the elements in the array.
For each test case, print “Yes” (without quotes) if a pair of such distinct indices (described in the problem statement) exists otherwise print “No” (without quotes).
Output for every 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 <= 50
1 <= N <= 10000
1 <= K <= 10000
0 <= ARR[i] <= 10^9
Where 'ARR[i]' denotes the ith element of the given array.
Time limit: 1 sec
The basic idea of this approach is to iterate through all the possible pairs of indices and check if duplicate elements exist satisfying the given constraint in the problem statement.
Consider the following steps:
The basic idea of this approach is to use a HashMap to store the index of the elements of the array/list so that we can very efficiently check if a particular element exists in the array/list or not. We will maintain a HashMap to store the pair<element, index>. Next, we will start traversing the array/list and check if the current element exists in the HashMap and the absolute difference of the index of that element and the current index is less than or equal to ‘K’. And each iteration will update the HashMap with a pair of current elements and index.
Consider the following steps:
‘j’ = indexOfElement[ARR[i]]