Find the Highest Point from Altitude Changes. Begin at altitude zero. The entries of gain are the altitude changes on successive route legs. Return the highest altitude reached at any route point, including the starting point.
### Problem
Begin at altitude zero. The entries of `gain` are the altitude changes on successive route legs. Return the highest altitude reached at any route point, including the starting point.
```cpp
class Solution {
public:
int largestAltitude(vector<int>& gain);
};
```
### Examples
**Example 1:**
```text
gain = [3,-1,4,-8]
Output: 6
Explanation: Altitudes are 0, 3, 2, 6, and -2.
```
**Example 2:**
```text
gain = [-2,-3,1]
Output: 0
Explanation: Every later point is below the starting altitude.
```
### Constraints
- `n == gain.length`, with `1 <= n <= 100`.
- `-100 <= gain[i] <= 100`.
### Clarifying Questions
The array contains changes rather than absolute heights. There are n+1 route points for n gains.
```hint Inspect the structure
Which route points must be considered when the starting altitude is zero?
```
### Reasoning checkpoints
- Evaluate altitudes at route points rather than treating individual gains as heights.
- Include the initial zero in the maximum.
### Optional extensions
How would you return the earliest route point reaching the maximum?
Overview: Find the Highest Point from Altitude Changes. Begin at altitude zero. The entries of gain are the altitude changes on successive route legs. Return the highest altitude reached at any route point, including the starting point.
Begin at altitude zero. The entries of gain are the altitude changes on successive route legs. Return the highest altitude reached at any route point, including the starting point.
class Solution {
public:
int largestAltitude(vector<int>& gain);
};
Examples
Example 1:
gain = [3,-1,4,-8]
Output: 6
Explanation: Altitudes are 0, 3, 2, 6, and -2.
Example 2:
gain = [-2,-3,1]
Output: 0
Explanation: Every later point is below the starting altitude.
Constraints
n == gain.length
, with
1 <= n <= 100
.
-100 <= gain[i] <= 100
.
Clarifying Questions Guidance
The array contains changes rather than absolute heights. There are n+1 route points for n gains.
Reasoning checkpoints
Evaluate altitudes at route points rather than treating individual gains as heights.
Include the initial zero in the maximum.
Optional extensions
How would you return the earliest route point reaching the maximum?