Python clean code easy understand
Intuition\nTo solve this problem, we can use a greedy algorithm with two variables to keep track of the maximum length of subarrays where the product of all ele
# Intuition\nTo solve this problem, we can use a greedy algorithm with two variables to keep track of the maximum length of subarrays where the product of all elements is positive or negative. The key is to consider the effects of positive, negative, and zero values on the product.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Initialize Variables:\npos_len: Length of the longest subarray ending at the current index with a positive product.\nneg_len: Length of the longest subarray ending at the current index with a negative product.\nmax_len: Maximum length of a subarray with a positive product found so far.\n\n2. Iterate through the Array:\nIf the current number is positive, extend the pos_len by 1. If neg_len exists, extend it by 1 as well (it will remain negative).\nIf the current number is negative, swap pos_len and neg_len since multiplying by a negative number flips the product\'s sign, and update them.\nIf the current number is zero, reset both pos_len and neg_len to 0 since the product becomes undefined.\n\n3. Update Maximum Length:\nUpdate max_len to the maximum value of itself and pos_len.\n\n4. Return the Result:\nAfter the loop, max_len contains the length of the longest subarray with a positive product.\n\n\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(1)\n\n# Code\n```python3 []\nclass Solution:\n    def getMaxLen(self, nums: List[int]) -> int:\n        pos_len = 0\n        neg_len = 0\n        max_len = 0\n\n        for num in nums:\n            if num > 0:\n                pos_len += 1\n                neg_len = neg_len + 1 if neg_len > 0 else 0\n            elif num < 0:\n                new_pos_len = neg_len + 1 if neg_len > 0 else 0\n                neg_len = pos_len + 1\n                pos_len = new_pos_len\n            else:  # num == 0\n                pos_len = 0\n                neg_len = 0\n            \n            max_len = max(max_len, pos_len)\n        \n        return max_len\n\n```
['Array', 'Greedy', 'Python3']