Problem · Array

Focus on Correctness (2024 NG)

Learn this problem
EasyGoogleFULLTIMEOA
See Google hiring insights

Problem statement

Given an array of digits, select up to 3 digits to form a number without changing their order. Return the largest possible number.

Note - When doing the assessment, they ask you to write your own test cases :)

Function

largestNumberPossible(digits: int[]) → int

Examples

Example 1

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

The largest number that can be formed by selecting up to 3 digits without changing their order is 749.

Constraints

  • 1 ≤ digits.length ≤ 10^5
  • 0 ≤ digits[i] ≤ 9
  • The relative order of selected digits must match their order in the input array.

More Google problems

drafts saved locally
public int largestNumberPossible(int[] digits) {
  // write your code here
}
digits[7, 2, 3, 3, 4, 9]
expected749
checking account