Highest Altitude using C++
Notes:
Altitude: It is generally the height achieved by an object from the reference level.
Gain: It is the altitude achieved during the journey, it can be posi
# Notes:
1. Altitude: It is generally the height achieved by an object from the reference level.
2. Gain: It is the altitude achieved during the journey, it can be positive or negative. 
3. Negative gain: when the biker moves downhill.
4. positive gain:  when the biker moves uphill.

# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
In the problem we are given an integer array gain of length n where gain[i] is the net gain in altitude between points i​​​​​​ and i+1.  we are expected to return the highest altitude of a point.

- we initially start from point 0(sea level). 
- We are given an array gain which consists of altitudes achieved by biker, it can be positive or negative.
- We need to return the highest altitude of the biker in the complete journey.
- To find the max altitude we can add the altitude at the previous step plus the gain at the current step. Starting from 0 and adding the gain at each step.
- After each addition, we will update the max altitude.

# Pattern Used:
 is Prefix Sum pattern in DSA.
# Approach
<!-- Describe your approach to solving the problem. -->
- 1st we initialise currentAltitude = 0 and maxAltitude = 0
- Then we iterate over the gains in altitude, add the gain[i] to currentAltitude 
- next we update the maxAltitude.
- finally we return the maxAltitude which is been asked to find in the problem.

# Complexity
- Time complexity: It is O(n) where n is the size of the gain array, as we iterate over the elements in gain only once.

- Space complexity: It is O(1). 
- Here gain array is provided as input and doesn't contribute to additional space complexity.
- currentAltitude, maxAltitude These take a fixed amount of space, regardless of the size of the input.
- Therefore overall space complexity is O(1).

# Code
```cpp []
class Solution {
public:
    int largestAltitude(vector<int>& gain) {
         int currentAltitude = 0;
         int maxAltitude = 0;
         for (int i = 0; i < gain.size(); i++) {
            currentAltitude= currentAltitude + gain[i];
            maxAltitude = max(maxAltitude, currentAltitude);
             }
    return maxAltitude;
    }
};
```
['C++']