


You are given a sorted array ARR of integers of size N and an integer K. You have to find whether it is possible to find a pair of integers having an absolute difference of K.
Note:
1. K is a non-negative integer.
2. Absolute Difference between two integers A and B is equal to the difference of maximumOf(A, B) and minimumOf(A, B).
3. Pair of integers should have different indices in the array.
The first line of input contains an integer T, denoting the number of test cases.
The first line of each test case consists of two space-separated integers N and K, denoting the size of the given array ARR and the required absolute difference.
The second line of each test case consists of N space-separated integers denoting the elements of the array.
Output format:
For each test case print, “Yes” if it is possible to have a pair of integers having absolute difference equal to K and “No” otherwise, in a separate line.
Note:
You don't have to print anything, it has already been taken care of. Just Implement the given function.
1 <= T <= 100
1 <= N <= 10^4
1 <= ARR[i] <= 10^9
0 <= K <= 10^9
Time Limit: 1 sec.
1
3 2
1 2 3
Yes
In the given array absolute difference of 1 and 3 equals to 2, which is required K.
1
4 6
2 3 3 5
No
As there is no pair of integers present in the given array whose absolute difference is K (which is 6 here).
Check for all possible pairs of integers in the array, if the absolute difference is K or not.
O(N^2), where N is the size of the given array.
As there are N^2 different pairs possible in the array of size N, hence this will take the time of order O(N^2).
O(1), as we are using constant extra memory.