c++ solution
\n\n# Approach\n Describe your approach to solving the problem. \nInitialize a vector of length n+1 with all values 0. This vector denotes all the altitudes. \n
\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nInitialize a vector of length n+1 with all values 0. This vector denotes all the altitudes. \nCalculate the net gain in altitudes at all points and return the max value from it.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(n)\n\n# Code\n```\nclass Solution {\npublic:\n    int largestAltitude(vector<int>& gain) {\n        int n = gain.size();\n        vector<int> altitude(n+1, 0);\n        for(int i = 0; i<gain.size(); i++){\n            altitude[i+1] = altitude[i] + gain[i];\n        }\n        return *max_element(altitude.begin(), altitude.end());\n    }\n};\n```
['C++']