Description

A biker goes on a road trip with altitude gains given in an array gain. Starting at altitude 0, return the highest altitude reached.

Examples

Input:gain = [-5,1,5,0,-7]
Output:1
Explanation:

Altitudes: 0,-5,-4,1,1,-6. Max is 1.

Input:gain = [-5, 1, 5, 0, -7]
Output:1
Explanation:

Altitudes: 0, -5, -4, 1, 1, -6. The highest altitude reached is 1.

Input:gain = [3, 2, -4, 1, -1]
Output:5
Explanation:

Starting at altitude 0, the altitudes are: 0 → 3 → 5 → 1 → 2 → 1. The highest altitude reached is 5.

Constraints

  • n == gain.length
  • 1 ≤ n ≤ 100

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!