FunctionRacerProblemsRace

Two Numbers From Four Digits

BeginnerGreedyPython, JavaScript, TypeScript, Java, C++

digits holds exactly four digits, each from 0 to 9. Use every one of them exactly once to write two numbers of two digits each, then add the two numbers. A number may start with 0, so the digits 0 and 7 can make 07, which is worth 7.

Return the smallest sum you can get.

Example 1

digits [2,9,3,2]
returns 52

The smallest digits, 2 and 2, go in front: 23 + 29 = 52. No other arrangement gives less.

Example 2

digits [4,0,0,9]
returns 13

The two zeros go in front: 04 + 09 = 13.

Example 3

digits [1,1,1,1]
returns 22

Every arrangement gives 11 + 11 = 22.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Greedy problems