FastPrepBiggest Number From Digits

Biggest Number From Digits

Google logoGoogle● EasyNEW GRADINTERNOA

Problem statement

You are given an array digits containing N decimal digits. Choose at most three elements, not necessarily adjacent, without changing their relative order. Concatenate the chosen digits and interpret the result as an integer.

Return the largest integer that can be formed this way.

Function

biggestNumberFromDigits(digits: int[]) → int

Examples

Example 1

digits = [7, 2, 3, 3, 4, 9]return = 749

Choose 7, 4, and 9 in their original order to form 749, the largest possible value.

Example 2

digits = [0, 0, 5, 7]return = 57

Choose 5 and 7 in their original order to form 57. Including either leading zero does not produce a larger integer.

Constraints

  • 3 <= N == digits.length <= 50
  • 0 <= digits[i] <= 9

More Google problems

See Google hiring insights
Saved
public int biggestNumberFromDigits(int[] digits) {
  // write your code here
}
digits[7, 2, 3, 3, 4, 9]
expected749
Checking account…