C++ two pass solution (with comments) | O(N) time and O(1) space
\n\nclass Solution {\npublic:\n    int getMaxLen(vector<int>& nums) {\n        int n = nums.size();\n        \n\t\t// sign will store 1 if curr product is posit
```\n\nclass Solution {\npublic:\n    int getMaxLen(vector<int>& nums) {\n        int n = nums.size();\n        \n\t\t// sign will store 1 if curr product is positive else -1\n        int sign = 1;\n\t\t// s_idx store starting of curr subarray (to handle cases when a 0 is encountered)\n        int s_idx = -1;\n\t\t// max_len will store max len of required subarray encountered till now\n        int max_len = 0;\n        for(int i=0; i<n; i++) {\n\t\t\t//flip sign if negative numver encountered\n            if(nums[i] < 0) {\n                sign *= -1;\n            }\n\t\t\t// if 0 encountered update s_idx\n            else if(nums[i] == 0) {\n                s_idx = i;\n                sign = 1;\n            }\n            \n            if(sign == 1) {\n               max_len = max(max_len, i - s_idx);\n            }\n        }\n        \n\t\t// same logic as above just we are doing right to left traversal\n        int e_idx = n; sign = 1;\n        for(int i=n-1; i>=0; i--) {\n            if(nums[i] < 0) {\n                sign *= -1;\n            }\n            else if(nums[i] == 0) {\n                e_idx = i;\n                sign = 1;\n            }\n            \n            if(sign == 1) {\n               max_len = max(max_len, e_idx - i);\n            }\n        }\n        \n        return max_len;\n    }\n};\n\n\n```
[]