100% faster solution | Java
Runtime: 0 ms, faster than 100.00% of Java online submissions...\n\nMaintain array for altitude.\nFind max altitiude in the same iteration as updating altitiude
**Runtime: 0 ms, faster than 100.00% of Java online submissions...**\n\n*Maintain array for altitude.\nFind max altitiude in the same iteration as updating altitiude array elements.*\n\n```class Solution {\n    public int largestAltitude(int[] gain) {\n        \n        int n = gain.length+1;\n        \n        int[] alt = new int[n];\n        \n        alt[0] = 0;\n        int ans = 0;\n        int k = 1;      //index for altitude array\n        int maxx = 0;\n        \n        for(int i = 0; i<n-1; i++){\n            \n            alt[k] = alt[k-1] + gain[i];\n            maxx = Math.max(maxx, alt[k]);\n            k++;\n        }\n        \n        return maxx;\n    }\n}
['Java']