Fully Explained Solution || Using simple concept of odd and even || O(n) Solution
Resources: https://github.com/AJAYKR00KJ/LeetCode_Solution\n\nWe can have only two possibilities in a subarray\n \n The count of negative number is even ,produc
***Resources: https://github.com/AJAYKR00KJ/LeetCode_Solution***\n\n**We can have only two possibilities in a subarray**\n \n* The count of negative number is even ,**product will be +ve** \n* Count of negative numberis odd ,**product will be -ve**\n\nUsing this concept I have written this solution with all necessary comments\nHoping It will be helpful to you.\n\n\n\n```\nclass Solution {\npublic:\n    int getMaxLen(vector<int>& nums) {\n        int mx=0;  //will store result\n        int sz=nums.size();\n        for(int i=0;i<sz;i++)\n        {     \n              int n_s=-1,n_e=-1,n=0,p=0,j;\n         \n              //n_s ->to store starting of negatiive number\n              //n_e ->to store end of negative number\n              //n   ->count of negative number\n              //p   ->count of positive number\n         \n         //We will iterate until we found zero \n              for(j=i;j<sz;j++)\n              {    \n                  if(nums[j]<0) n++;\n                  if(nums[j]>0)p++;\n                  if(nums[j]<0&&n_s==-1) { n_s=j;} //store starting index of negative number\n                  if(nums[j]<0) n_e=j;             //store end index of negative number\n                  if(nums[j]==0) break;          //subarray ends now because after that all the product will be 0  \n              }\n             // cout<<i<<" "<<n_s<<" "<<n_e<<" "<<j<<" : "<<n<<" "<<p<<"\\n";\n         \n             /* Here only two possibilities */\n            \n             /* 1.if we have even number of negative \n                multiply of even negative numbers are positive, so add both n and p and take max of res \n             */\n             if(n%2==0) mx=max(mx,n+p);\n          \n             /*\n               2.if we have negative numbers and count of these are odd ,\n               Lets say subarray -> {1,2,-1,2,3,1,-1,2,3,4,-1,2,3} , I am taking 3 negative numbers\n               We know that odd-1 = even\n               We have stored starting of negative number index in n_s\n               and end of negative number index in n_e\n               \n               For this example n_s=2 , n_e = 10\n               So here two cases, if we left a negative number of n_s index then \n               total count of negative numbers will be odd-1=even negative numbers \n               i.e subarray will be {2,3,1,-1,2,3,4,-1,2,3}\n               \n               Or if we left a negative number of n_e index than\n               total count of negative numbers will be odd-1=even negative numbers \n               i.e subarray will be {1,2,-1,2,3,1,-1,2,3,4}\n               \n               So max length will be any one from these two only\n               So we will take max length of these two\n             */\n             if(n%2==1)\n             {\n                  mx=max(j-n_s-1,mx);\n                  mx=max(n_e-i,mx);\n             }\n             //cout<<mx<<" ";\n           i=j; //now starting from new subarray\n        }\n         \n        \n        return mx;\n    }\n};\n```\n\n**If any improvement needed please comment**\n \n\n***Time Complexity : O(n)\nSpace Complexity: O(1)***\n
['C', 'Sliding Window', 'C++']