Highest Point of the Hike

EasyRunning Totals≈ 10 min

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

text
changes = [-5, 1, 5, 0, -7]           →  1
changes = [-4, -3, -2, -1, 4, 3, 2]   →  0
changes = [3, 4, -2]                  →  7

In 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.
Sound off. Turn on for key clicks and a chime when the tests pass.Inline suggestions off. Recommended while you are learning. Turn on to complete words as you type.
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.