FunctionRacerProblemsRace

Largest Multiple of Three

HardMathPython, JavaScript, TypeScript, Java, C++

Every item of digits is a digit from 0 to 9. Choose one or more of the items, each at most once, and write them in any order to make a number.

Return the largest multiple of 3 that can be made, as a string with no extra zeros at the front. If none can be made, return "".

Example 1

digits [7,2,4]
returns "72"

The digits add up to 13. Leaving out the 4 brings that to 9, and 72 is the larger way to write 7 and 2.

Example 2

digits [2,2,3,6]
returns "63"

The digits add up to 13 and no single digit fixes that. Leaving out both 2s brings it to 9.

Example 3

digits [4]
returns ""

4 is not a multiple of 3, and there is no other digit to use.

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 Math problems