Runtime: 0 ms, faster than 100.00% of Java online submissions
\nint max = 0;  \n        int sum = 0;\n        for(int i=0;i<gain.length;i++){\n            sum = sum + gain[i];\n            if(sum>max)\n                max=
```\nint max = 0;  \n        int sum = 0;\n        for(int i=0;i<gain.length;i++){\n            sum = sum + gain[i];\n            if(sum>max)\n                max=sum;\n        }\n        return max;\n```\n\n**Upvote** if it was helpful.
['Java']