
The first line contains a single integer ‘T’ representing the number of test cases.
The first line of each test case will contain three integers ‘N’, ‘K’, and ‘L’ where ‘N’ is the number of elements in the array and the integers ‘K’ and ‘L’ are described 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 don’t need to print anything; It has already been taken care of. Just implement the given function.
1 <= T <= 50
1 <= N <= 10000
0 <= K <= 10000
0 <= L <= 10^9
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 pair elements exist satisfying the given constraint in the problem statement. Consider the following steps:
The basic idea of this approach is to use an ordered_map to store the index of the elements of the array/list so that we can very easily find if the lower/upper bound of a particular element exist or not. So we will maintain an ordered_map which will contain elements such that the difference between the largest and smallest index is less than ‘K’.
Let us start traversing the given array/list and assume that we are currently at j-th index and we are trying to find an element with index ‘i’ such that pair (i, j) satisfies the condition given in the problem statement. Now we need to check if there is an element at any index ‘i’ such that ‘j’ - ‘K’ <= ‘i’ < ’j’ and ARR[j] - ‘L’ <= ARR[i] <= ARR[j] + ‘L’. Since we are maintaining a sliding window of ordered_map which contains all the elements of subarray [j - ‘K’, ‘j’ - ’1’] we can easily find if an element within a particular range exists or not.
Consider the following steps :