Beats 100% + Video of Prefix Sum| Java C++ Python
Approach\nThe altitude at any given point = sum of all pervious points in array. Keep track of max to track ans.\n\n1. Initiate altitude = 0 and max = 0.\n2. fo
# Approach\nThe altitude at any given point = sum of all pervious points in array. Keep track of max to track ans.\n\n1. Initiate altitude = 0 and max = 0.\n2. for i in arr: altitude+= arr[i]\n3. max = Math.max(altitude, max) \n4. return max\n\n<iframe width="560" height="315" src="https://www.youtube.com/embed/_Kfiw07DulY" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>\n\n```\nclass Solution {\n    public int largestAltitude(int[] gain) {\n        int altitude = 0;\n        int max = 0;\n        for(int i: gain){\n            altitude +=i;\n            max = Math.max(altitude, max);\n        }\n        return max;\n    }\n}\n```\n\n```\nclass Solution {\npublic:\n    int largestAltitude(std::vector<int>& gain) {\n        int altitude = 0;\n        int max = 0;\n        for(int i : gain) {\n            altitude += i;\n            max = std::max(altitude, max);\n        }\n        return max;\n    }\n};\n```\n\n```\nclass Solution:\n    def largestAltitude(self, gain):\n        altitude = 0\n        max_altitude = 0\n        for i in gain:\n            altitude += i\n            max_altitude = max(altitude, max_altitude)\n        return max_altitude\n```
['C', 'Python', 'Java']