Optimal C++ Solution. This is EZ
pos means the length of longest subarray ending at current index with positive product. Similar for neg.\n\nclass Solution {\npublic:\n    int getMaxLen(vector<
`pos` means the length of longest subarray ending at current index with positive product. Similar for `neg`.\n```\nclass Solution {\npublic:\n    int getMaxLen(vector<int>& A) {\n        int ans = 0, pos = 0, neg = 0;\n        for (int &e : A) {\n            if (e > 0) {\n                pos = pos > 0 ? pos + 1 : 1;\n                neg = neg > 0 ? neg + 1 : 0;\n            } else if (e < 0) {\n                int pp = pos, nn = neg;\n                pos = nn > 0 ? nn + 1 : 0;\n                neg = pp > 0 ? pp + 1 : 1;\n            } else {\n                pos = neg = 0;\n            }\n            ans = max(ans, pos);\n        }\n        return ans;\n    }\n};\n```
['C']