Highest Point of the Hike
A hike starts at altitude 0. The list changes holds how much each stretch of the trail climbs (a positive number) or drops (a negative number), in the order they are walked. Return the highest altitude reached at any point of the hike, the start included.
Examples
changes = [-5, 1, 5, 0, -7] → 1
changes = [-4, -3, -2, -1, 4, 3, 2] → 0
changes = [3, 4, -2] → 7In the first example the altitudes are 0, -5, -4, 1, 1, -6, and the highest is 1. In the second the trail never climbs above where it started.
Constraints
- Between 0 and 10,000 stretches, each changing the altitude by between -1,000 and 1,000.
- Aim for O(n): one addition per stretch.
Console
›Run to see what your code prints
Run checks the 3 visible cases here, in your browser. Submit runs all 7 on the judge, 4 of them hidden, and measures how your solution scales.
Expected is the reference solution's answer, from the judge. An input that breaks the statement's other rules may get any answer.