← DiffPush

Largest element in array

Baseline Arrays · Easy O(n) · O(1)

Peak Draw on the Solar String

A solar farm streams one ampere reading per panel into a rolling buffer each minute. The hardware team needs the single highest reading the string ever produced so they can size the inline fuse. Return that peak value.

Input: An integer n followed by an array A of n integer readings.

Output: A single integer: the maximum element of A.

Constraints

Examples

Example 1

Input: {"n":5,"A":[1,8,7,56,90]}
Output: 90
Scanning the five readings, 90 is the highest value encountered.

Example 2

Input: {"n":6,"A":[4,15,8,23,16,42]}
Output: 42
The peak sits at the end of the buffer, so the scan cannot stop early.

Solve this in your browser →

Also on LeetCode ↗