[Python] DP - O(1) Space - Clean & Concise
python\nclass Solution:\n    def getMaxLen(self, nums: List[int]) -> int:\n        def getMaxLenNonZero(left, right):  # left, right inclusive, nums[left:right+
```python\nclass Solution:\n    def getMaxLen(self, nums: List[int]) -> int:\n        def getMaxLenNonZero(left, right):  # left, right inclusive, nums[left:right+1] doesn\'t contain zero\n            if left > right: return 0\n            negMap = {}\n            negMap[0] = left - 1\n            ans = 0\n            nevCnt = 0\n            for i in range(left, right+1):\n                if nums[i] > 0:\n                    ans = max(ans, i - negMap[nevCnt])\n                else:\n                    nevCnt = 1 - nevCnt\n                    if nevCnt not in negMap:\n                        negMap[nevCnt] = i\n                    ans = max(ans, i - negMap[nevCnt])\n            return ans\n        \n        n = len(nums)\n        left = 0\n        ans = 0\n        while left < n:\n            while left < n and nums[left] == 0:\n                left += 1\n            if left == n: break\n            right = left + 1\n            while right < n and nums[right] != 0:\n                right += 1\n            # now, right == n or nums[right] == 0\n            ans = max(ans, getMaxLenNonZero(left, right - 1))\n            left = right + 1\n        \n        return ans\n```\nComplexity:\n- Time: `O(N)`, where `N <= 10^5` is length of `nums` array.\n- Space: `O(1)`
[]