using dp, prefixsum
Code\n\nclass Solution:\n    def findMaximumLength(self, nums: List[int]) -> int:\n        nums+=[float(\'inf\')]\n        presum=[0]+list(accumulate(nums))\n\n
## Code\n```\nclass Solution:\n    def findMaximumLength(self, nums: List[int]) -> int:\n        nums+=[float(\'inf\')]\n        presum=[0]+list(accumulate(nums))\n\n        n, dp, prev, cur = len(nums)-1, Counter(), Counter(), 0\n\n        for i in range(n):\n            i+=1\n            cur=max(cur,prev[i])\n            dp[i]=(i-cur-1) + dp[cur]\n            idx=bisect.bisect_left(presum,2*presum[i]-presum[cur])   \n            prev[idx]=i\n        return n-dp[n]\n```
['Python3']