Skip to content
Decoder

Find the Highest Altitude

Easy

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.length
  • 1 <= n <= 100
  • -100 <= gain[i] <= 100

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.