Minimum sum
Submissions: 3191   Accuracy:

20.29%

  Difficulty: Medium   Marks: 4

Given an array of digits (values are from 0 to 9). Find the minimum possible sum of two numbers formed from digits of the array. All digits of given array must be used to form the two numbers.

Input:
The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consist of two lines. The first line of each test case consists of an integer N, where N is the size of array.
The second line of each test case contains N space separated integers denoting array elements.

Output:
For each testcase, print the minimum possible sum of two numbers formed from digits of the array.

Constraints:
1 ≤ T ≤ 300
1 ≤ N ≤ 107
0 ≤ Ai ≤ 9

Example:
Input
:
1
5
5 3 0 7 4
Output:
82

Explanation:
Testcase 1: 35 and 47 gives the smallest sum out of all possible combinations of numbers. Their sum is 82.

** For More Input/Output Examples Use 'Expected Output' option **

Author: rajatjha


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.