Java || O(1) space || O(n) time || Beats 90% of solutions
Idea is based on Kadane\'s algorithm\nWe iterate through all the elements\n We maintain two variables one without excluding an element(maxSum) and other with ex
**Idea is based on Kadane\'s algorithm**\nWe iterate through all the elements\n* We maintain two variables one without excluding an element(maxSum) and other with excluding atmost one element(maxSumWithAtmostOneDel)\n* Update maxSum by adding current element\n* Update maxSumWithAtmostOneDel by taking maximum of :\n       1)Including the current element, so adding the current element to sum with excluding atmost element upto previous element\n       2)Excluding the current element, so considering maxSum upto previous element\n* Reset reset the maxSum to zero if it goes into negative value\n* Update the result if any of the above mentioned two cases are greater than the current result \n* We maitain the maximum of all elements to handle all negative case, so returning the maximum of all in that case\n\n\n```\nclass Solution {\n    public int maximumSum(int[] arr) {\n        int maxSum = 0;\n        int maxSumWithAtmostOneDel = 0;\n        int maxEle = Integer.MIN_VALUE;\n\t\tint result = 0;\n\t\t\n        for (int num : arr) {\n            maxEle = Math.max(maxEle, num);\n            \n            maxSumWithAtmostOneDel = Math.max(maxSum, maxSumWithAtmostOneDel + num);\n            maxSum += num;\n            \n            if(maxSum < 0) {\n                maxSum = 0;\n            }\n            result = Math.max(result, Math.max(maxSumWithAtmostOneDel, maxSum));;\n        }\n        \n        if(maxEle <= 0) {\n            return maxEle;\n        }\n        return result;\n    }\n```
[]