Loading
Loading
A drone logs its altitude change after each leg of a flight. A positive value means it climbed that many metres; a negative value means it descended.
The drone starts at altitude 0. Return the highest altitude it ever reaches during the flight, including the starting altitude.
changes = [-5, 1, 5, 0, -7]0start-5after leg 1-4after leg 21after leg 3 — highest so far1after leg 4-6after leg 51Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(n) time · O(1) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
Altitudes are 0, -5, -4, 1, 1, -6. The highest is 1.
Example 2
The drone only descends before climbing back, so the starting altitude of 0 is never beaten.