FastPrepMaximum Number in a Large File

Maximum Number in a Large File

Google logoGoogle● EasyNEW GRADPHONE SCREEN
Learn

Problem statement

A very large text file contains one signed integer per line. Return the maximum integer in the file.

The practice runner supplies the parsed lines as an array numbers. Your algorithm should use constant auxiliary space so the same logic can process a file as a stream without loading every line at once.

Function

maximumFileNumber(numbers: long[]) → long

Examples

Example 1

numbers = [-5,7,2]return = 7

Seven is larger than the other file values.

Example 2

numbers = [42]return = 42

A one-line file returns its only number.

Example 3

numbers = [-9,-3,-12]return = -3

The maximum can still be negative.

Constraints

  • 1 <= numbers.length <= 1000000.
  • Every value fits in a signed 64-bit integer.

More Google problems

See Google hiring insights
public long maximumFileNumber(long[] numbers) {
    // Write your code here.
}
numbers[-5,7,2]
expected7
Checking account…