Ctrl K

Two Numbers From Four Digits

Easy
You get a four-digit number code. Distribute its four digits into two new numbers: every digit is used exactly once, digits inside a new number may go in any order, and leading zeros are allowed (05 is simply 5). The two new numbers may have different lengths. For instance, 2932 can become 22 and 93, 223 and 9, or 2 and 329. Return the smallest possible sum of the two new numbers.
Example 1
code=3715 → 52

For example 13 + 57 = 70, while 15 + 37 = 52 (as does 17 + 35). Nothing below 52 is possible, since the two smallest digits 1 and 3 sit in the tens places.

Example 2
code=6002 → 8

Zeros are best used as leading digits: 02 + 06 = 2 + 6 = 8.

Constraints
  • 1000 ≤ code ≤ 9999
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsTriangle From Sticks EasySmallest Sum From Splitting the Digits EasyUp or Down for Every Post MediumRound Prices to a Total MediumSparse Ones in a Grid Hard
loading Python…
Input
code=3715
Expected
52

Run checks the first 3 tests in your browser. Submit checks all 85 tests on the server, hidden ones included.