Find the Highest Altitude
A hiker starts at altitude 0. Item gain[i] of the list gain is the net change in altitude between point i and point i + 1 of the trip (positive means climbing).
Return the highest altitude reached at any point, counting the start.
Example 1
gain [-5,1,5,0,-7]
returns 1
Altitudes: 0, -5, -4, 1, 1, -6. The highest is 1.
Example 2
gain [-3,-2]
returns 0
The start (0) is the highest.
Constraints
1 <= len(gain) <= 30-20 <= gain[i] <= 20
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Arrays problems
- Groups of KBeginner
- Items Within BudgetBeginner
- Kids With the Most CandiesBeginner
- Largest At Least Twice OthersBeginner
- Longest Increasing RunBeginner
- Max Consecutive OnesBeginner
- Peak So FarBeginner
- Running Sum of an ArrayBeginner