C++ Solution
Intuition\n- The intuition was that for a particular subarray to have positive product it should have even number of negative elements, the positive elements ca
# Intuition\n- The intuition was that for a particular subarray to have positive product it should have even number of negative elements, the positive elements can be odd or even any.\n\n# Approach\n- For a subarray\n- If negatives are even find the length of the subarray as that array will have positive product\n- Else if the subarray has odd negatives then make the subarray with even negatives by excluding either the first or the last negative element in the subarray that we encountered and then calcualte the max length of the subarray among the two\n- Handle the case when we encounter 0 as we dont want a subarray with value 0 in it\n\n# Complexity\n- Time complexity: O(N)\n- Space complexity: O(1)\n\n# Code\n```\nclass Solution {\npublic:\n    int getMaxLen(vector<int>& nums) {\n        int n = nums.size();\n        int result = 0;\n        for(int i=0;i<n;){\n            int start = i;\n            while(start<n && nums[start]==0)    start++;\n\n            int end = start , nf = -1 , nl = -1;\n            int count = 0;\n            while(end<n && nums[end]!=0){\n                if(nums[end]<0){\n                    count++;\n                    if(nf==-1)  nf = end;\n                    nl = end;\n                }\n                end++;\n            }\n            if(count%2==0){\n                result = max(result,end-start);\n            }else{\n                if(nf!=-1)      result = max(result,end-(nf+1));    // excluding the first negative that we found\n                if(nl!=-1)      result = max(result,nl-start);     // excluding the last negative that we found\n            }            \n             \n            i = end + 1;\n        }\n\n        return result;\n    }\n};\n```\n# PLEASE UPVOTE!!!\n
['Array', 'Greedy', 'C++']