<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>

static auto fastio = []() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
};
class Solution {
public:
    int getMaxLen(vector<int>& nums) {
        fastio();
        int n = nums.size();
        int len = INT_MIN;
        deque<int> dq, dq1;
        bool f = false;
        for (int i = 0; i < n; i++) {
            if (nums[i] == 0) {
                if (dq1.empty()) {
                    len = max(len, int(dq.size()));
                    dq.clear();
                } else {
                    int sz = dq1.size();
                    if (sz % 2 == 0) {
                        len = max(len, int(dq.size()));
                    } else {
                        // remove last occurence of negative number.
                        int bkMinus = dq1.back();
                        int bkall = dq.back(), sz = dq.size();
                        len = max(len, sz - (bkall - bkMinus + 1));
                        // remove first occurence of negative number.
                        int ftMinus = dq1.front(), bkall1 = dq.front();
                        len = max(len, sz - (ftMinus - bkall1 + 1));
                    }
                }
                dq1.clear();
                dq.clear();
            } else {
                if (nums[i] < 0)
                    dq1.push_back(i);
                dq.push_back(i);
            }
        }
        if (dq1.empty()) {
            len = max(len, int(dq.size()));
            dq.clear();
        } else {
            int sz = dq1.size();
            if (sz % 2 == 0) {
                len = max(len, int(dq.size()));
                
            } else {
                // remove last occurence of negative number.
                int bkMinus = dq1.back();
                int bkall = dq.back(), sz = dq.size();
                len = max(len, sz - (bkall - bkMinus + 1));
                // remove first occurence of negative number.
                int ftMinus = dq1.front(), bkall1 = dq.front();
                len = max(len, sz - (ftMinus - bkall1 + 1));
                
            }
        }
        return len;
    }
};
62700