C++ easy code O(n)
Let us understand this case by case.\n3 cases would be possible,\n if element is positive\n \tthen do nothing and just keep moving forward as this will give us 
Let us understand this case by case.\n*3 cases would be possible*,\n* if element is positive\n \tthen do nothing and just keep moving forward as this will give us a larger result.\n* if element if zero\n\tthen reinitiate everything, that is make count of negative=0, make lastneg (firsneg) as -1.\n* if element if negative\n1. \tthen first of all, increase the count ie (negative++)\n2. \tif this count is 1, then we see the index of previous negative, if it is not yet initialised ie its value is -1, then we assign its value as i+1,\n3. \tnow if count of negatives is even then we take this whole subarray,\n\t**else if count of negatives is odd, then we take help of prevneg, which means we have excluded the first negative from our subarray which now makes count of negatives in our subarray as even.**\n\t\n\tafter taking all max possible length of subarrays possible, we return the final answer.\n\t\n\n```\nclass Solution {\npublic:\n    int getMaxLen(vector<int>& a) {        \n      int n=a.size();\n      int pos=0,neg=0,ans=0,j=0;\n      int lastneg=-1;\n      for(int i=0;i<n;i++){\n        if(a[i]==0){\n          j=i+1;\n          lastneg=-1;\n          pos=0,neg=0;\n        }\n        else if(a[i]>0) pos++;\n        else {\n          neg++;\n          if(neg%2==1 and lastneg==-1) lastneg=i+1;\n        }\n        if(neg%2==0) {\n          ans=max(ans,i-j+1);\n        }\n        else if(lastneg!=-1) ans=max(ans,i-lastneg+1);\n      }\n      return ans;\n    }\n};\n```\n
['Greedy']