[JAVA] [DYNAMIC PROGRAMMING]  AN EASY SOLUTION WITH EXPLANATION !!
// here the basic idea is to check if number of negative values present in array is divisible by 2 or not.\n// if yes then we will add them to our result as we 
// here the basic idea is to check if number of negative values present in array is divisible by 2 or not.\n// if yes then we will add them to our result as we know product of 2 negative values will always be a positive.\n// we can check it with the help of (neg[i] & 1)==0 or (neg[i] %2)==0\n// if yes the we will update our result\n//else we check for next value\n\n\n// here we have applied 2 pass\n\n//in first pass we are iterating from left to right and checking is value is nums[i] i.e the current number is positive or not.\n//if yes then we are increasing the positive count \n// if not then we are increasing the negative count\n// and checking if number of negative values are even or not\n\n\n// in second pass we are iterating from right to left making the exact same procedure what we did in first pass.\n// second pass is necessary as to make sure we have not allowed any value to change our result\n\n// if the result from pass 1 is equal to pass 2, then the value of res will not change\n//but if it has changed then it will be updated in pass2.\n\n\nclass Solution {\n\n    public int getMaxLen(int[] nums) {\n        \n        int res =0;\n        int n = nums.length;\n        int[] pos = new int[n+1];\n        int[] neg = new int[n+1];\n        \n        for(int i=1;i<n+1;i++)\n        {\n            if(nums[i-1]>0)\n            {\n                pos[i] =pos[i-1]+1;\n                neg[i] = neg[i-1];\n            }\n            if(nums[i-1]<0)\n            {\n                neg[i] = neg[i-1]+1; \n                pos[i] = pos[i-1];\n            }\n            \n            if((neg[i] & 1)==0)\n            {\n                res = Math.max(res,pos[i]+neg[i]);\n            }\n        }\n        \n        Arrays.fill(pos,0);\n        Arrays.fill(neg,0);\n        \n        for(int i=n-1;i>=0;i--)\n        {\n            if(nums[i]>0)\n            {\n                pos[i] = pos[i+1]+1;\n                neg[i] = neg[i+1];\n            }\n            if(nums[i]<0)\n            {\n                neg[i] = neg[i+1]+1;\n                pos[i] = pos[i+1];\n            }\n            if((neg[i] & 1)==0)\n            {\n                res = Math.max(res,pos[i]+neg[i]);\n            }\n        }\n        return res;\n    }\n}\n\nPlease upvote if you like the solution and let me know in comments if any doubt
[]