Fully explained C++ solution | Easy to understand
Split the whole array into subarrays by zeroes since a subarray with positive product cannot contain any zero.\n2. We count no of negative numbers in each subar
1. Split the whole array into subarrays by zeroes since a subarray with positive product cannot contain any zero.\n2. We count no of negative numbers in each subarray. If the count is even than the product of whole subarray is positive.\n3. If it is odd we have 2 options , either we remove all elements from starting to first negative number or we remove all elements from last negative number to end of the subarray.\n\n```\nint getMaxLen(vector<int>& nums) {\n        int ans = 0;\n        int n = nums.size();\n        \n        for(int i=0;i<n;){\n            int s = i; //s is the starting index of subarray\n            int c = 0; //c will keep count of no of negative numbers\n            \n            //ignore zeroes in starting of the array\n            while(s<n and nums[s] == 0) s++;\n            \n            int e = s; //e will be used to traverse the subarray\n            int sn = -1; //index of 1st negative no\n            int ln = -1; //index of last negative no\n            \n            while(e<n and nums[e] != 0){\n                \n\t\t\t\t//when we encounter a negative no we increament c\n                if(nums[e] < 0){\n                    c++;\n                    if(sn == -1) sn = e;  //first negative number\n                    ln = e;\n                }\n                \n                e++;\n            }\n            \n            //now e(end) will either point to 0 or n\n            \n            //if no of negatives in subarray are even\n            if(c%2 == 0){\n                ans = max(ans, e-s);\n            }\n            else{\n                \n                //remove first negative no\n                if(sn != -1){\n                    ans = max(ans , e-sn-1);\n                }\n\t\t\t\t\n                 //OR  \n                //remove last negative no\n                if(ln != -1){\n                    ans = max(ans , ln-s);\n                }\n            }\n            \n            i = e; //now i will point to the index next to the last element of the current subarray\n        }\n        return ans;\n    }\n```\n\nTime Complexity - O(n)  since every element is traversed only once\nSpace Complexity - O(1)\n\n**Please upvote if you find the solution helpful!**
['C']