Quiz
Min and Max Sum Pair
Submissions: 281   Accuracy:

37.37%

  Max. Score:

30

You are given an array of size n. You need to find two elements(pair) whose sum is minimum and two elements(pair) whose sum is maximum. You need to output the min sum and max sum.

Input:
The first line of the input contains a single integer T, denoting the number of test cases. Then T test case follows. Each testcase contains size of array n. The next line contains the elements of the array.

Output:
For each testcase, print the min sum of pair and max sum of pair.

Constraints:
1<=T<=200
2<=n<=104
0<=A[i]<=104

Example:

Input:
1

4
3 1 4 2

Output:
3 7

Explanation:
For testcase1:
The total pairs of 3 with other elements are: (3,1); (3,4); (3,2). So sum = 4; 7; 5 respectively
The total pairs of 1 with other elements are: (1,4); (1,2). So sum = 5; 3 respectively
The total pairs of 4 with other elements are: (4,2). So sum = 6
Clearly, the min pair sum is 3 and the max pair sum is 7.

 


to report an issue on this page.