A vending machine dispenses four tokens, each stamped with a single digit from 0 to 9. A technician must combine the four tokens into exactly two badges. Each badge is formed by placing one token in its tens slot and a second token in its ones slot, producing a two-digit number (a badge showing tokens 0 and 5, for instance, represents the number 5 -- leading zeros are allowed and do not remove the badge from consideration). Every token is used in exactly one slot of exactly one badge, and all four tokens must be used.
Determine the minimum possible sum of the two badge numbers.
A single line containing four integers d_1, d_2, d_3, d_4, each between 0 and 9 inclusive, separated by spaces -- the digits on the four tokens, in the order they were dispensed.
A single integer: the minimum possible sum of the two badge numbers obtainable by grouping the four tokens into two badges.
Example 1
Input
2 4 3 7
Expected
61
Explanation
Sorting the digits gives 2, 3, 4, 7. Placing the two smallest digits (2 and 3) in the tens slots and the two largest (4 and 7) in the ones slots produces badges 24 and 37 (equivalently 27 and 34), which sum to 61 -- the minimum possible total.
Example 2
Input
5 5 5 5
Expected
110
Explanation
All four tokens show the digit 5, so any grouping produces two badges reading 55, and 55+55=110 is the only -- and therefore minimum -- possible sum.
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 →