Problem
A cyclist starts a ride at altitude 0. You are given gain, where gain[i] is the net change in altitude between point i and point i + 1. Return the highest altitude reached at any point, including the start.
Example 1
- Input
- gain = [-5, 1, 5, 0, -7]
- Output
- 1
- Why
- altitudes 0, -5, -4, 1, 1, -6
Example 2
- Input
- gain = [-4, -3, -2, -1, 4, 3, 2]
- Output
- 0
- Why
- never climbs above the start
Constraints
n == gain.length1 <= n <= 100-100 <= gain[i] <= 100