Beats 100% using C++
Intuition\nCumulative Calculation: The algorithm effectively keeps a running total of the altitude changes. By continuously adding each gain to the current alti
# Intuition\nCumulative Calculation: The algorithm effectively keeps a running total of the altitude changes. By continuously adding each gain to the current altitude, you can easily track how the altitude evolves over time.\nDynamic Tracking: By updating max whenever curr exceeds it, you ensure that you capture the highest point reached at any stage in the journey.\nLinear Time Complexity: The solution runs in O(n) time, where n is the length of the gain array. This is efficient since it only requires a single pass through the array\n\n# Approach\nExample Walkthrough\nConsider the gain array: [-5, 1, 5, 0, -7].\n\nStarting Altitude: 0\nChanges:\nAfter -5: curr = 0 - 5 = -5 \u2192 max = 0\nAfter 1: curr = -5 + 1 = -4 \u2192 max = 0\nAfter 5: curr = -4 + 5 = 1 \u2192 max = 1\nAfter 0: curr = 1 + 0 = 1 \u2192 max = 1\nAfter -7: curr = 1 - 7 = -6 \u2192 max = 1\nThe maximum altitude reached is 1.\n\n# Complexity\n- Time complexity: $$O(n)$$ \n\n- Space complexity: $$O(1)$$\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int largestAltitude(vector<int>& gain) {\n        int max=0;\n        int curr=0;\n        for(int i =0 ; i<gain.size(); i++){\n            curr+=gain[i];\n            max=std::max(curr,max);\n        }\n        return max;\n    }\n};\n```
['C++']