[Java] Most of answers are trying to convey the idea of Dynamic Programming!!
We definitely can use Dynamic Programming here, by using 2 arrays: dp_positive represents the max length of positive product ending at index i; dp_negative repr
We definitely can use Dynamic Programming here, by using 2 arrays: **dp_positive** represents the max length of positive product ending at index i; **dp_negative** represents the max length of negative product ending at index i. \n```\n    public int getMaxLen(int[] nums) {\n        int res = 0;\n        int len = nums.length;\n        int[] dp_positive = new int[len], dp_negative = new int[len];\n        // initilization:\n        if (nums[0] > 0) {\n            dp_positive[0] = 1;\n        } else {\n            dp_negative[0] = 1;\n        }\n        \n        // dynamid equation & transition:\n        for (int i=1; i<len; i++) {\n            if (nums[i] > 0) {\n                dp_positive[i] = dp_positive[i-1] + 1;\n                if (dp_negative[i-1] > 0) dp_negative[i] = dp_negative[i - 1] + 1;\n                else dp_negative[i] = 0;\n            } else if (nums[i] < 0) {\n                dp_negative[i] = dp_positive[i-1] + 1;\n                if (dp_negative[i-1] > 0) dp_positive[i] = dp_negative[i - 1] + 1;\n                else dp_positive[i] = 0;\n            }\n            res = Math.max(res, dp_positive[i]);\n        }\n        return res;\n    }\n```
[]