


Suppose ‘N’ = 5, ‘A’ = [1,2,3,4,5], and target = 8
As target == A[2] + A[4] = 3 + 5 = 8.
Hence output will be 2 4.
The first line of the input contains a single integer ‘T’ representing the no. of test cases.
The first line of each test case contains two space-separated integers, ‘N’ and ‘Target’, denoting the size of ‘A’ and the target sum value.
The second line of each test case contains ‘N’ space-separated integers representing the elements of ‘A’.
For each test case, print two space-separated integers denoting the indices of elements of ‘A’, which add up to ‘target’.
Print a separate line for each test case.
You are not required to print anything; it has already been taken care of. Just implement the function and return the answer.
1 ≤ T ≤ 1000
1 ≤ N ≤ 100000
-1000 ≤ A[i] ≤ 1000
ΣN ≤ 300000
Time limit: 1 Sec
We are using a classical approach of two pointers. The inspiration for this kind of approach simply comes from the fact that A[i] + A[j] == target, then for any index k > i. Its complement can only be in the range <= j, which further translates to the following lemma- “for the increasing value of i the index of its complement can only decrease”. Thus we can keep two pointers at the start for i and the other j at the end for the complement. As we can only decrease j at most O(N) times and increase i O(N) times, the time should also be linear. Implementation details will be as per the following algorithm.
The steps are as follows: