Python Hard
\nclass Solution:\n    def findMaximumLength(self, nums: List[int]) -> int:\n        N = len(nums)\n        dp = [1] * (N + 1)\n        pref = [0] + list(accumu
```\nclass Solution:\n    def findMaximumLength(self, nums: List[int]) -> int:\n        N = len(nums)\n        dp = [1] * (N + 1)\n        pref = [0] + list(accumulate(nums))\n        prev = [0] * (N + 1)\n\n        for i in range(N):\n            if dp[i + 1] < dp[i]:\n                dp[i + 1] = dp[i]\n                prev[i + 1] = prev[i]\n\n            elif dp[i + 1] == dp[i]:\n                prev[i + 1] = max(prev[i + 1], prev[i])\n\n            prev_total = pref[i + 1] - pref[prev[i + 1]]\n            \n            index = bisect_left(pref, prev_total + pref[i + 1])\n\n            if index >= len(pref):\n                continue\n\n            if dp[i + 1] + 1 > dp[index]:\n                dp[index] = dp[i + 1] + 1\n                prev[index] = i + 1\n            \n            elif dp[i + 1] + 1 == dp[index]:\n                prev[index] = max(prev[index], i + 1)\n\n\n            \n\n        return max(dp)\n\n            \n\n            \n\n\n          \n```
['Python3']