<p>Given an array of integers <code>nums</code>, find the maximum length of a subarray where the product of all its elements is positive.</p>

<p>A subarray of an array is a consecutive sequence of zero or more values taken out of that array.</p>

<p>Return <em>the maximum length of a subarray with positive product</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,-2,-3,4]
<strong>Output:</strong> 4
<strong>Explanation:</strong> The array nums already has a positive product of 24.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [0,1,-2,-3,-4]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The longest subarray with positive product is [1,-2,-3] which has a product of 6.
Notice that we cannot include 0 in the subarray since that&#39;ll make the product 0 which is not positive.</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> nums = [-1,-2,-3,0,1]
<strong>Output:</strong> 2
<strong>Explanation:</strong> The longest subarray with positive product is [-1,-2] or [-2,-3].
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
	<li><code>-10<sup>9</sup> &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
</ul>

class Solution:
    def getMaxLen(self, nums: List[int]) -> int:
        n = len(nums)
        zeros = []
        for i in range(n):
            if(nums[i]==0):
                zeros.append(i)

        def maxSub(arr):
            if(len(arr)==0):
                return 0

            if(len(arr)==1):
                if(arr[0]>0):
                    return 1

                else:
                    return 0

            l = len(arr)
            pre = [0 for i in range(l)]
            if(arr[0]<0):
                pre[0] = 1

            for i in range(1, l):
                if(arr[i]<0):
                    pre[i] = (pre[i-1]+1)%2

                else:
                    pre[i] = pre[i-1]

            res = 0
            ends = {}
            for i in range(l):
                if(pre[i] not in ends):
                    ends[pre[i]] = [i, i]

                else:
                    ends[pre[i]][1] = i

            if 0 in ends:
                res = max(res, ends[0][1]+1)

            if 1 in ends:
                res = max(res, ends[1][1] - ends[1][0])

            print(arr, ends)
            return res


        z = len(zeros)
        if(z==0):
            return maxSub(nums)

        ans = 0
        for i in range(z):
            if(i==0):
                ans = max(ans, maxSub(nums[:zeros[i]]))

            else:
                ans = max(ans, maxSub(nums[zeros[i-1]+1:zeros[i]]))


        ans = max(ans, maxSub(nums[zeros[-1]+1:]))
        return ans

            
            
525