100 % beat and simple solution
Intuition\n Describe your first thoughts on how to solve this problem. \n1.Inplace prefix sum calculation\n2.Use Math.max function\n# Approach\n Describe your a
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n1.Inplace prefix sum calculation\n2.Use Math.max function\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. for i=1\narr[1]=arr[1]+arr[0]\n2. for i=2\narr[2]=arr[2]+arr[1]  //here arr[1] is itself changed in previous formula if u r confused then think about substitution\n1. for i=3\narr[3]=arr[2]+arr[1]\n4. illy for upto i=n-1(length of array)\n5. After that iterate over every elements of prefix sum array and using math.max function compare and store the max element in max variable\n6. At last return max variable\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n), here n is length of given array\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1) ,No extra space used (Inplace operation)\n\n![9d32a68c-a698-414f-b82f-e7ecc693f3eb_1687147131.7430437.png](https://assets.leetcode.com/users/images/5fe1780f-9ce2-4278-bd93-23b040cae640_1724465218.4350731.png)\n# Code\n```java []\nclass Solution {\n    public int largestAltitude(int[] gain) {\n        int n=gain.length,max=0;\n        for(int i=1;i<n;i++){\n            gain[i]+=gain[i-1];\n        }\n        for(int i=0;i<n;i++){\n        max=Math.max(max,gain[i]);\n        }\n        return max;\n    }\n}\n```\n\n
['Java']