[C++] Single Pass Solution Explained, 100% Time, 65% Space
To solve this problem, we will need 2 variables, both initialised to 0:\n res is our accumulator, storing the maximum altitude seen so far;\n curr is the curren
To solve this problem, we will need 2 variables, both initialised to `0`:\n* `res` is our accumulator, storing the maximum altitude seen so far;\n* `curr` is the current altitude.\n\nFor each element `n` in `gain`, we will:\n* update `curr` with `n`;\n* updated `res` so that it is going to be the highest value between itself and `curr`.\n\nOnce done, we can return `res` :)\n\nThe code:\n\n```cpp\nclass Solution {\npublic:\n    int largestAltitude(vector<int>& gain) {\n        // support variables\n        int res = 0, curr = 0;\n        for (int n: gain) {\n            // updating curr\n            curr += n;\n            // updating res\n            res = max(res, curr);\n        }\n        return res;\n    }\n};\n```
['C', 'C++']