Problem of the day
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
3
5 4
5 7 9 1 3
4 2
8 10 11 1
6 -7
-3 3 6 -5 -4 1
YES
NO
YES
For the first array [5,7,9,1,3] there exists a pair (1,3) whose sum is equal to 4.
For the second array, there exists no pair whose sum is equal to 2.
For the third array, there exists a pair (-3,-4) whose sum is equal to -7.
3
6 -10
3 4 5 6 1 2
2 0
10 -10
4 -20
5 6 7 1
NO
YES
NO