<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:
        #Brute force
        #maxlen = 0
        #for i in range(len(nums)):
        #    for j in range(i+1, len(nums)+1):
        #        product = reduce(lambda x,y: x*y, nums[i:j], 1)
        #        print(i, j, j-i, product)
        #        if product > 0 and j-i > maxlen:
        #            maxlen = j-i
        #print(maxlen)
        #return maxlen
        
        #Iterative

        #Split nums into non-zero sections, since a subarray with zero can never be positive
        lastSpot = 0
        numNegatives = 0
        maxes = []
        for i in range(len(nums)):
            num = nums[i]
            print(i, num, lastSpot, numNegatives)
            if num == 0:
                if (i - lastSpot) > 0:
                    maxes.append(self.processSubRange(nums[lastSpot:i], numNegatives))
                lastSpot = i+1
                numNegatives = 0
            elif num < 0:
                numNegatives += 1
        if len(nums) - lastSpot > 0:
            maxes.append(self.processSubRange(nums[lastSpot:], numNegatives))
        maxes.append(0)
        #print(maxes)
        return max(maxes)
    
    def processSubRange(self, nums, nn):
        print(nums)
        if nn % 2 == 0:
            return len(nums)
        #map numbers to even odd
        nums = [i for i in map(lambda x: 0 if x > 0 else 1, nums)]
        #print(nums)
        #Find leftmost negative number
        left_index = nums.index(1)
        #Find rightmost negative number
        right_index = self.rightIndex(nums, 1)
        #print(left_index, right_index)
        #Calculate what the biggest section would be
        #assert left_index != -1 and right_index != -1
        #print(left_index)
        #print(len(nums) - left_index - 1)
        #print(right_index)
        #print(len(nums) - right_index - 1)
        max_section = max([
            left_index,
            len(nums) - left_index - 1,
            right_index,
            len(nums) - right_index - 1,
            0
        ])
        #print(max_section)
        return max_section


    def rightIndex(self, l, x):
        for i in range(len(l) - 1, -1, -1):
            if l[i] == x:
                return i
        return -1
    

622