

Alice took a sorted array = [4,6,8,10,11] and if she rotates it by 3, then the array becomes: [8, 10, 11, 4, 6].
The first line of input contains a single integer T, representing the number of test cases
Then the T test cases follow.
The first line of each test case contains a number N denoting the size of the array and an integer K representing the sum of pair.
The second line contains N space-separated distinct integers a1, a2, ..., aN — the array elements.
For each test case print “YES” if Bob finds the pair else print “NO”.
The output of every test case will be printed in a separate line.
You don’t have to print anything, it has already been taken care of. Just implement the given function.
Can you do this in O(N) time, and without using any extra space?
1<= T <=100
2 <= N <= 10000
-10^8 <= A[i] <= 10^8
-10^8 <= k <= 10^8
Time limit: 1 second
We will find all the possible pairs by iterating over the whole array N times. At any time if the sum of any pair is equal to K we will return TRUE else keep on iterating.
We will scan the array from left to right and we will use the Hash to store all previously encountered elements. So at each step, we find a value say REQ = k - (current element), and see if REQ already exists in Hash.
We will find the index of the shortest element and as we know that the index of the largest element will always be 1 less than the index of the shortest element.
Now we can use two pointer technique to find the pair whose sum is k in a single scan. But we have to care that indices can go less than 0 or more than N - 1. So we will be using modular operation (IDX % N where IDX is an index of the array) to always keep indices in the valid range.