Python Sol by tracking +ve & -ve subarray lengths.
Intution:\nIn this problem it is easy to confuse yourself with keeping track of products and starting indices for subarray . However we do not need to keep trac
### Intution:\nIn this problem it is easy to confuse yourself with keeping track of products and starting indices for subarray . However we do not need to keep track of the product or the indices, what we need is to track the length, **JUST THE LENGTH**. Since products are involved in this problem keep track of -ve & +ve subarray length seperately. Also if value becomes zero it is obvious that the subarray needs to reset at next index. We could simply use the facts that `-ve X +ve = +ve` & `-ve X -ve = +ve` & `+ve X +ve = +ve` while maintaining the sizes of -ve and +ve product subarrays during the traversal\n### Explaination:\nKeep two variables pos and neg that stores the lengths of +ve & -ve product subarrays respectively. Now we loop through the array and we can get 3 possible cases:\n1. `value == 0`: We simply reset the subarray by making neg = pos = 0\n2. `value > 0`: The new +ve product subarray is the old +ve product subarray + current_value, so `pos += 1`. Similarly if -ve prodcut subarray exists then its length also increases by 1 as -ve X +ve = -ve.\n3. `value < 0`: The new +ve product subarray is the old -ve product subarray + current_value as -ve X -ve = +ve, so `pos = neg+1`. However if `neg == 0`(no -ve product subarray exists) then `pos = 0`. Similarly the new -ve product subarray is the previous +ve product subarray + current_value as +ve X -ve = -ve. Thus `neg = pos+1`(must be done before updating the pos value)\nAt each iteration we also recheck for max_len.\n\n**So basically, if `val == 0` -> Reset the subarrays || if `val > 0` -> +ve subarray remains +ve and -ve remains -ve after adding the new value || if `val < 0` -> +ve subarray becomes -ve and -ve becomes +ve after adding the new value due to sign reversal.**\n\n### Code:\n```\nclass Solution:\n    def getMaxLen(self, nums: List[int]) -> int:\n        max_len = pos = neg = 0\n        for i in nums:\n            if i == 0: # Case 1 -> Reset the subarrays\n                pos = neg = 0\n            elif i > 0: # Case 2 -> +ve subarray remains +ve and -ve remains -ve after adding the new value\n                pos += 1 # increment pos\n                neg = 0 if neg == 0 else neg + 1 # neg remains 0 if it is already 0 otherwise increment it.\n            else: # Case 3 -> +ve subarray becomes -ve and -ve becomes +ve after adding the new value due to sign reversal.\n                old_pos = pos\n                pos = 0 if neg == 0 else neg + 1 # pos becomes 0 if it is neg is 0 otherwise it is neg+1\n                neg = old_pos + 1 # neg becomes old pos + 1\n            max_len = max(max_len, pos) # Update the max_len \n        return max_len \n```
['Python', 'Python3']