Largest Multiple of Three

Given an array of digits digits, return the largest multiple of three that can be formed by concatenating some of the given digits in any order. If there is no answer, return an empty string.

Since the answer may not fit in an integer data type, return the answer as a string. The returned answer must not contain unnecessary leading zeros.

Example 1
Inputdigits = [8,1,9]
Output"981"
Using all digits in the order 9, 8, 1 forms 981, which is the largest possible multiple of three.
Example 2
Inputdigits = [8,6,7,1,0]
Output"8760"
Using digits 8, 7, 6, and 0 forms 8760, which is the largest possible multiple of three.

Constraints

  • 1 <= digits.length <= 10^4
  • 0 <= digits[i] <= 9

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate