Python DP left and right continuous subarray, optimized with O(1) space solution
python\nimport math\n\nclass Solution:\n    def maximumSum(self, arr: List[int]) -> int:\n        n = len(arr)\n        left, right = arr.copy(), arr.copy()\n  
```python\nimport math\n\nclass Solution:\n    def maximumSum(self, arr: List[int]) -> int:\n        n = len(arr)\n        left, right = arr.copy(), arr.copy()\n        for i in range(1,n):\n            left[i] = max(left[i], left[i]+left[i-1])\n        for i in range(n-2,-1,-1):\n            right[i] = max(right[i], right[i]+right[i+1])\n        res = -math.inf\n        i = -1\n        while i <= n:\n            l, r = -math.inf, -math.inf\n            if i > 0:\n                l = left[i-1]\n            if i < n-1:\n                r = right[i+1]\n            res = max(res,l,r,l+r)\n            i += 1\n        return res\n```\nOptimized with O(1) space solution, dp0 and dp1 respresent the current subarray sum with 0 and 1 element removed respectively.\n\n```python\nclass Solution:\n    def maximumSum(self, arr: List[int]) -> int:\n        n = len(arr)\n        dp0, dp1, res = arr[0], 0, arr[0]\n        for i in range(1,n):\n            dp0, dp1 = max(dp0+arr[i], arr[i]), max(dp0,dp1+arr[i])\n            res = max(dp0, dp1, res)\n        return res\n```
[]