✅ BEATS 100% OF SOLUTION ☑️
PLEASE UPVOTE MY SOLUTION IF YOU LIKE IT\n# CONNECT WITH ME\n### https://www.linkedin.com/in/pratay-nandy-9ba57b229/\n#### https://www.instagram.com/pratay_nand
# **PLEASE UPVOTE MY SOLUTION IF YOU LIKE IT**\n# **CONNECT WITH ME**\n### **[https://www.linkedin.com/in/pratay-nandy-9ba57b229/]()**\n#### **[https://www.instagram.com/pratay_nandy/]()**\n\n# Approach\nExplanation:\n\n1. **Variable Initialization:**\n   - `maxi`: It represents the maximum altitude reached during the iteration. Initialized to 0.\n   - `sum`: It represents the cumulative altitude gain. Initialized to 0.\n\n2. **Iterate Through the Gain Vector:**\n   - The `for` loop iterates through each element in the `gain` vector.\n\n3. **Update Cumulative Altitude Gain:**\n   - `sum += gain[i];`: Add the current gain value to the running sum, representing the cumulative altitude gain.\n\n4. **Update Maximum Altitude:**\n   - `maxi = max(maxi, sum);`: Update the `maxi` variable with the maximum altitude reached so far. It uses the `max` function to compare the current `sum` with the existing `maxi` and stores the larger of the two.\n\n5. **Return Maximum Altitude:**\n   - After the loop completes, the function returns the maximum altitude reached (`maxi`).\n\nThe function essentially calculates the cumulative altitude gain during the iteration through the `gain` vector and keeps track of the maximum altitude reached. The final result is the maximum altitude reached during the entire journey.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:**0(N)**\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:**0(1)**\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int largestAltitude(vector<int>& gain) {\n        int maxi = 0;\n        int sum = 0;\n        for(int i = 0 ;i < gain.size();i++)\n        {\n            sum += gain[i];\n            maxi = max(maxi,sum);\n        }\n        return maxi;\n        \n    }\n};\n```
['Array', 'Prefix Sum', 'C++']