A biker goes on a road trip made of n + 1 points at different altitudes. The biker starts at point 0 with altitude 0. You are given an integer array gain of length n where gain[i] is the net gain in altitude between points i and i + 1. Return the highest altitude of any point.
A biker goes on a road trip made of n + 1 points at different altitudes. The biker starts at point 0 with altitude 0. You are given an integer array gain of length n where gain[i] is the net gain in altitude between points i and i + 1. Return the highest altitude of any point.
Example 1:
Input: {"gain":[-5,1,5,0,-7]}
Output: 1
Constraints:
n==gain.length
1≤n≤100
−100≤gain[i]≤100
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"gain":[-5,1,5,0,-7]}
The trip starts at point 0, at altitude 0. That starting point already counts, so the highest altitude so far is 0.