
The first line contains a single integer ‘T’ representing the number of test cases.
The first line of each test case will contain one integer ‘N’ and ‘X’, that denotes the size of the ‘ARR’ and runs you need to come close to with the help of your team.
The second line of each test case contains ‘N’ space-separated integers ‘ARR[i]’, which denoting the numbers present in our ‘ARR’.
For each test case, return a pair of integers denoting the closest pairs of values which have the highest runs combined.
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.
1 <= T <= 5
1 <= N <= 10^5
0 <= A[i], X <= 10^9
Time Limit: 1 sec
The basic idea of this approach is to iterate the whole ‘ARR’ from start and check for all the elements present after it. If the sum of the current pair is less than or equal to ‘X’ minus 30 then we will check if it is less than our temporary answer or not. If it is less then we will replace it with a temporary answer.
Here is the algorithm:
The basic idea of this approach is to initially sort the whole ‘ARR’ and then using two pointers we will try to get all the nearby possible pairs giving sum ‘X’ - 30. With the help of a two pointer approach, we will get only valid nearby possible pairs and thus, iterating two loops can be reduced to one loop.
Here is the algorithm: