C++ clear solution, one-pass, time O(n), space O(1)
The theory is simple:\n- The subarray cannot contain 0, otherwise the product will be 0. So we divide the array into sections by 0s, and try to find max subarra
The theory is simple:\n- The subarray cannot contain 0, otherwise the product will be 0. So we divide the array into sections by 0s, and try to find max subarray length of each section.\n- For each section (now only contains positive and negative numbers)\n\t- If we find even number of negative numbers, the prodution of **all numbers** in this section will be positive, thus maxLen is length of the whole section\n\t- If the number of negative numbers is odd, the maxLen will be either **from the start of section to the number before last negative number** or **from the next number after first negative till end of the section**.\n\nThis is a one-pass solution, each number is inspected once. Time complexity O(n), space complexity O(1).\n\n```cpp\nint getMaxLen(vector<int>& nums) {\n    int maxLen = 0;\n    for (int sectionStart = 0; sectionStart < nums.size(); ) {\n        while (sectionStart < nums.size() && !nums[sectionStart]) sectionStart++; // ignore leading 0s\n\t\t\n        int evenNeg = 0;            // flag for even or odd number of negative we\'ve seen in this section\n        int first = -1, last = -1;  // indices of first and last negative number so far\n        int i = sectionStart;\n        for (; i < nums.size(); i++) {\n            if (!nums[i]) break;    // 0, this section is done\n            if (nums[i] < 0) {\n                evenNeg ^= 1;\n                (first < 0) && (first = i);\n                last = i;\n            }\n        }\n        maxLen = max(maxLen, evenNeg ? max(last - sectionStart, i - first - 1) : i - sectionStart);\n        sectionStart = i + 1;\n    }\n    return maxLen;\n}\n```\n
['C']