C++ || DP-O(N)  || EXPLAINED WHAT I UNDERSTOOD
\n```\n->I am accepting that I wasn\'t able to solve this question at one go but i tried a lot of methodS and finally I reached the O(N) dp solution I understoo
\n```\n->I am accepting that I wasn\'t able to solve this question at one go but i tried a lot of methodS and finally I reached the O(N) dp solution I understood the best \n->Let\'s Begin\n->First of all we need to clarify the terms and our goal...\n->So my goal is to get thte longest subarray length with positive product. Hence we will be concerned more about the posLen which is the  length of subarray with  positive product  till now and negLen which means length of subarray with negative product  till now..\n->negLen will be helping us to encounter the situtations like -3*-10=30 giving us a increment in subarray length...\n->Consider the array [1,2,-3,4,-5,8,-6,0,7]\nLets code run the above example:\n1. \'1\' , enters 1st condition , made posLen=1, negLen=0 as there was no negative elem \n2. \'2\', enters 1st condition, made posLen=2, negLen=0\n3. \'-3\', enters 2nd condition, made posLen=0 (since the resultant sum for the subarray [1,2,-3] in any way will be negative, hence in this case posLen is determined by negLen means if there exists a negative no. before), negLen=3 (and this will be determined by posLen previously as it is eating up all the positive nos.)\n4. \'4\', enters 1st condition, made posLen=1 (means the subarray [4] is having a positive multiplication and its length is 1), negLen=4 ([1,2,-3,4]==>-24)\n5. \'-5\', enters 2nd condition, made posLen=5 (since negative length subarray is existing and multipliying it with a negative no. make it positive), negLen=2(this may be confusing, but its simple, as we want to calculate the subarray we donot want to lose track of any subarray count, hence its actually [4,-5] that is negative subarray)\n6. \'8\', enters 1st condition, made posLen=6 ([1,2,-3,4,-5,8]), negLen=3 ([4,-5,8])\n7. \'-6\', enters 2nd condition, made posLen=4 (since negative exists, giving it a direction to make longestLenSubArray using [4,-5,8,-6]), negLen=7 (i.e., 1+prevPosLen)\n8. \'0\', enters 3rd condition, made posLen and negLen both as 0\n9. Finally \'7\', posLen=1, negLen=0\n\n\tint getMaxLen(vector<int>& nums) {\n\t\tint posLen=(nums[0]>0)?1:0;  //since 1st elem is +ve giving posLen=1\n\t\tint negLen=(nums[0]<0)?1:0;  //negLen=0\n\t\tint res=posLen;  //incase there is only one element [5], hence returning 1 in this case\n\t\tfor(int i=1;i<nums.size();i++)\n\t\t{\n\t\t\tif(nums[i]>0)  //if the current no. is +ve, then we have to update positive and negative \n\t\t\t//1)if previously the product is +ve and the cur no. is also positive then, just increment the posLen by 1. At idx 1, there is 2 which is indeed a positive giving us a result of positive hence we wil be including it in posLen...\n\t\t\t//2)if the previous product is -ve and the current no. is +ve, then obviously we\'ll be updating the negLen by 1 but if the previous product is not -ve then we\'ll be making negative as 0.\n\t\t\t{\n\t\t\t\tposLen=1+posLen;\n\t\t\t\tnegLen=(negLen)?1+negLen:0;\n\t\t\t}\n\t\t\telse if(nums[i]<0)  //if the current no. is -ve, then we\'ll be updating posLen using info we have in negLen, as if we have a negLen product of -10 and we\'ve cur no. as -3 then it will be making a positive no., hence we\'ll be updating the posLen=1+negLen as it is formed using a negative product\' subarray length\n\t\t\t//we\'ll be updating the negLen by 1+ (previously positives), since then only it\'ll be getting a negative product (-ve*+ve=-ve)\n\t\t\t{\n\t\t\t\tint temp=posLen;\n\t\t\t\tposLen=(negLen)?1+negLen:0;\n\t\t\t\tnegLen=1+temp;\n\t\t\t}\n\t\t\telse //if it is a zero just reset as anything product 0 is 0...\n\t\t\t{\n\t\t\t\tposLen=0; negLen=0;\n\t\t\t}\n\t\t\tres=max(res,posLen);  //storing the maximum length positve product subarray\n\t\t}\n\t\treturn res;\n\t}\n};
['C++']