A logistics hub receives a single combined manifest number, written as an ordinary positive integer with no leading zero, that must be broken apart into two separate manifest codes for two outbound trucks. Every digit of the original manifest number must end up in exactly one of the two new codes — none may be dropped, and none may be reused — but you are free to arrange the digits assigned to each code in whatever order you like when writing that code down. Each of the two resulting codes must receive at least one digit. Among all such splits, find one that minimizes the sum of the two resulting codes, read as ordinary integers, and report that minimum sum.
A single line containing the manifest number num, written as a string of decimal digits with no leading zero.
A single integer: the minimum possible sum of the two manifest codes.
num has between 2 and 10 digits)num has no leading zeroExample 1
Input
4325
Expected
59
Explanation
The digits are 4, 3, 2, 5. Sorting them ascending gives 2, 3, 4, 5; distributing them alternately (the 1st and 3rd sorted digits go to the first code, the 2nd and 4th to the second) gives codes "24" and "35". Their sum is 24 + 35 = 59, which is the minimum achievable over every way of splitting these four digits into two non-empty codes.
Example 2
Input
687
Expected
75
Explanation
The digits are 6, 8, 7. Sorted ascending: 6, 7, 8. Alternating gives the first code the 1st and 3rd sorted digits ("6" then "8", forming "68") and the second code the 2nd sorted digit ("7"). The sum 68 + 7 = 75 is the minimum possible.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →