<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:
        start, end = 0, 0
        best_result = 0
        while end < len(nums) and len(nums) - 1 - start >= best_result:
            last_end_idx = None
            cur_prod_sign = 1
            while end < len(nums):
                if nums[end] == 0:
                    break
                sign = 2 * ((nums[end] > 0) - 0.5)
                cur_prod_sign *= sign
                if cur_prod_sign > 0:
                    last_end_idx = end
                end += 1
            if last_end_idx is not None:
                best_result = max(best_result, last_end_idx - start + 1)
            old_sign = 2 * ((nums[start] > 0) - 0.5)
            start += 1
            if old_sign > 0:
                while start < len(nums) and old_sign * nums[start] > 0 and nums[start-1] != 0:
                    start += 1
            end = start
        return best_result
628