[Python3] 7-line O(N) time & O(1) space
Define two counters pos and neg as the length of positive and negative products ending at current element. \n\n\nclass Solution:\n    def getMaxLen(self, nums: 
Define two counters `pos` and `neg` as the length of positive and negative products ending at current element. \n\n```\nclass Solution:\n    def getMaxLen(self, nums: List[int]) -> int:\n        ans = pos = neg = 0\n        for x in nums: \n            if x > 0: pos, neg = 1 + pos, 1 + neg if neg else 0\n            elif x < 0: pos, neg = 1 + neg if neg else 0, 1 + pos\n            else: pos = neg = 0 # reset \n            ans = max(ans, pos)\n        return ans \n```
['Python3']