KatInterview

Find the Maximum Value in a Large Numerical Stream

Arrays & HashingAuto-graded · 18 test cases
EasyAuto-gradedArrays & Hashingarraysstreamingbasics

Last updated

Find the maximum integer in a sequence while accounting for empty inputs and signed values.

Given a list of signed 64-bit integers a, return the maximum value contained in the list.

If the list is empty, return None.

Constraints

  • $0 \le \text{len}(a) \le 10^5$
  • Each element in a fits within a standard signed 64-bit integer ($-2^{63} \le a[i] \le 2^{63} - 1$).

Examples

Example 1

Input: find_maximum_value([3, 1, 9, -4, 9])

Output: 9

Example 2

Input: find_maximum_value([-9223372036854776000, -1, 0, 9223372036854776000])

Output: 9223372036854776000

Example 3

Input: find_maximum_value([])

Output: None

Hints

Hint 1

Be careful not to initialize your running maximum to 0, as all numbers in the input might be negative.

Hint 2

Consider how to handle the edge case where the input list contains no elements.

Hint 3

Iterate through the array line-by-line or item-by-item, updating a single candidate variable.