FunctionRacerProblemsRace

Find the Highest Altitude

BeginnerArraysPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Arrays problems