Problem
A hiker walks a trail with n + 1 points. The hike starts at point 0, and the altitude of point 0 is 0. The altitude is the height of a point.
The item gain[i] is the change in altitude from point i to point i + 1. Return the highest altitude of all the points.
Example 1
- Input:
- gain = [3,-5,4,2,-1]
- Output:
- 4
- Explanation:
- The altitudes of the points are 0, 3, -2, 2, 4 and 3. The highest altitude is 4.
Example 2
- Input:
- gain = [-2,-3,-1]
- Output:
- 0
- Explanation:
- The trail only goes down. The start point, at altitude 0, is the highest point.
Constraints
- n == gain.length
- 1 <= n <= 100
- -100 <= gain[i] <= 100
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 1732. Find the Highest Altitude
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source