<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 {
public:
    int getMaxLen(vector<int>& nums) {
        int i,j,k,max = 1,mul = 1;
        i = 0;
        j = 0;
        if (nums.size() == 1)
        {
            if (nums[0] > 0)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        int g = 0;
        vector<int> vector1{};
        while(i < nums.size())
        {
            if (nums[i] < 0)
            {
                j ++;
            }
            if (j%2 == 0 && nums[i] != 0)
            {
                vector1.push_back(1);
            }
            else if (j%2 != 0 && nums[i] != 0)
            {
                vector1.push_back(-1);
            }
            else
            {
                vector1.push_back(0);
                j = 0;
                g ++;
            }
            i ++;
        }
        i = 0;
        if (g == vector1.size())
        {
            return 0;
        }
        int count1 = 0,count2 = 0;
        int x = 0,y = 0,a = 0,b = 0;
        while(i < vector1.size())
        {
         if (vector1[i] == 1)
         {
            count1 ++;
            if (count1 == 1)
            {
                x = i;
                if (count2 == 1)
                {
                    if (max < x-a+1)
                    {
                    max = x-a+1;
                    }
                }
                else if (count2 > 1)
                {
                    if (max < x - a+1)
                    {
                        max = x-a+1;
                    }
                }
            }
            else
            {
                y = i;
                if (max < y-x+1)
                {
                    max = y-x+1;
                }
                if (count2 == 1)
                {
                    if (max < y - a+1)
                    {
                        max = y-a+1;
                    }

                }
                else if (count2 > 1)
                {
                    if (max < y-a+1)
                    {
                        max = y-a+1;
                    }
                }
            }
            
         }
         else if (vector1[i] == -1)
         {
            count2 ++;
            if (count2 == 1)
            {
                a = i;
            }
            else
            {
                b = i;
                if (max < b-a)
                {
                    max = b-a;
                }
            }
         }
         else
         {
            count1 = 0,count2 = 0;
         }
         i ++;
        }
        
        return max;
    }
};
66000