C++ One pass with Explanation
See my latest update in repo LeetCode\n\n## Solution 1.\n\n We shouldn\'t include 0 in the subarray. So we just handle each of the subarrays surrounded by 0s.\n
See my latest update in repo [LeetCode](https://github.com/lzl124631x/LeetCode)\n\n## Solution 1.\n\n* We shouldn\'t include `0` in the subarray. So we just handle each of the subarrays surrounded by `0`s.\n* If there are even number of negative numbers in the subarray, the entire subarray has a positive product.\n* If there are odd number of negative numbers in the subarray, we have two candidates:\n    1. From the first element of the subarray to the element before the last negative element\n    2. From the next element of first negative element to the last element of the subarray.\n\n```cpp\n// OJ: https://leetcode.com/contest/weekly-contest-204/problems/maximum-length-of-subarray-with-positive-product/\n// Author: github.com/lzl124631x\n// Time: O(N)\n// Space: O(1)\nclass Solution {\npublic:\n    int getMaxLen(vector<int>& A) {\n        int j = 0, N = A.size(), ans = 0;\n        while (j < N) {\n            int i = j, cnt = 0, first = -1, last = -1;\n            while (j < N && A[j] != 0) {\n                cnt += A[j] < 0;\n                if (A[j] < 0) {\n                    if (first == -1) first = j;\n                    last = j;\n                }\n                ++j;\n            }\n            if (cnt % 2) ans = max({ ans, j - first - 1, last - i });\n            else ans = max(ans, j - i);\n            while (j < N && A[j] == 0) ++j;\n        }\n        return ans;\n    }\n};\n```
[]