Python O(n) simple solution
neg: Length of longest negative-product subarray ending with nums[i].\npos: Length of longest positive-product subarray ending with nums[i].\n\n\nclass Solution
`neg`: Length of longest *negative*-product subarray ending with `nums[i]`.\n`pos`: Length of longest *positive*-product subarray ending with `nums[i]`.\n\n```\nclass Solution:\n    def getMaxLen(self, nums: List[int]) -> int:\n        ans = neg = pos = 0\n        for x in nums:\n            if x > 0:\n                if neg > 0:\n                    neg += 1\n                pos += 1\n            elif x < 0:\n                neg, pos = pos+1, (neg+1 if neg else 0)\n            else:\n                neg = pos = 0\n            ans = max(ans, pos)\n        return ans\n```
['Dynamic Programming', 'Python3']