[C++] Dynamic Programming | Explained | O(N) Time | O(1) Space
\nclass Solution {\npublic:\n    int getMaxLen(vector<int>& nums) {\n        \n        int neg_len=0, neg_cnt=0, len=0;\n        //len: current length that is b
```\nclass Solution {\npublic:\n    int getMaxLen(vector<int>& nums) {\n        \n        int neg_len=0, neg_cnt=0, len=0;\n        //len: current length that is being considered for answer\n        //neg_cnt: number of times -ve nos appeared in the considered length (len)\n        //neg_len: length of the array from [(nums[x]=0) or begining] till first -ve number was encountered\n        \n        int ans=0; // maximum length of subarray with positive product\n        \n        for(int i=0; i<nums.size(); i++) {\n            //when num==0\n            if(nums[i]==0) {\n                len=0; neg_len=0; neg_cnt=0;\n                //as this can never be the part of subarray\n                continue;\n            }\n            \n            len++;\n            \n            //when num<0\n            if(nums[i]<0 && neg_len==0) neg_len=len; //first time -ve number appeared in the considered len\n            if(nums[i]<0) neg_cnt++;\n            \n            //calculating ans\n            if(neg_cnt%2) ans=max(ans, len-neg_len); //when odd number of -ve nos are present in len\n            else ans=max(ans, len); //when even number of -ve nos are present in len\n        }\n        return ans;\n    }\n};\n```\n\n*PLease upvote if you find this helpful\nFeel free to comment in case of any doubt*\n\n\nHappy Coding ```^_^```
['C']