


The first line of input contains an integer ‘T’, denoting the number of test cases.
The first line of each test case contains one integer ‘N’, denoting the size of the array.
The following line contains an array ‘A’ of ‘N’ spaced distinct integers.
For each test case, print a single integer in a new line denoting the maximum sum Bob can make by taking two integers from the array.
You are not required to print the expected output. It has already been taken care of. Just implement the function.
1 <= T <= 5
2 <= N <= 10^5
-10^9 <= A[i] <= 10^9
Time Limit: 1 sec
We need to take two elements from the array so that their sum is maximum. To do this, we can use two nested loops to check all possible pairs and store the maximum possible sum.
We need to find the array’s maximum and second maximum values in a single traversal. Let’s use two variables, to store the array’s maximum and second maximum values.
A few key observations are :