[Python] Short and Accurate Solution || Documented
Algorithm\n1. If we see a 0, we gotta start off things again\n2. If we see a positive number :\n2.1. Increase length of positive mutilpicative result till now.\
**Algorithm**\n1. If we see a 0, we gotta start off things again\n2. If we see a positive number :\n2.1. Increase length of positive mutilpicative result till now.\n2.2. Increase length of negative mutilpicative result till now, unless we had not encountered any negative before.\n3. If we see a negative number:\n3.1. It\'s time to swap positive and negative multiplicative results\' lengths and do similar task as we did in above case.\n4. In each iteration, use the length of positive mutilpicative result to compute answer.\n```\nclass Solution:\n    # Time O(n) Space O(1)\n    # neg: Length of longest negative-product subarray ending with nums[i].\n    # pos: Length of longest positive-product subarray ending with nums[i].\n    def getMaxLen(self, nums: List[int]) -> int:\n        pos = neg = res = 0                                     # reset result, len of +ve and -ve streak\n        for num in nums:\n            if num > 0:                                         # if num is +ve\n                pos += 1                                        # - add to +v streak; \n                neg += 1 if neg != 0 else 0                     # - add to -ve streak, if neg is not zero, else reset to 0\n            elif num < 0:                                       # if num is -ve\n                pos, neg = neg+1 if neg > 0 else 0, pos + 1     # reset pos if prevNeg > 0 and turn the entire +ve streak to -ve streak\n            else:\n                pos = neg = 0                                   # reset len of +ve and -ve streak\n                \n            res = max(res, pos)                                 # max length is in +ve streak\n        return res\n```\nPlease UPVOTE\uD83D\uDC4D if you love\u2764\uFE0F this solution or learned something new.\nIf you have any question, feel free to ask.
[]