My Java Solution O(n) and additional space
\nclass Solution {\n    public int getMaxLen(int[] nums) {\n        int n = nums.length; \n        int [] positive = new int [n+1];\n        int [] negative = n
```\nclass Solution {\n    public int getMaxLen(int[] nums) {\n        int n = nums.length; \n        int [] positive = new int [n+1];\n        int [] negative = new int [n+1];\n        int result = 0;\n        for (int i=1; i<=n; i++) {\n            if (nums[i-1] < 0) {\n                positive[i] = positive[i-1];\n                negative[i] = negative[i-1]+1;\n            }\n            else if (nums[i-1] > 0) {\n                positive[i] = positive[i-1]+1;\n                negative[i] = negative[i-1];\n            }\n            if (negative[i] % 2 == 0)\n                result = Math.max(result, positive[i] + negative[i]);\n        }\n        Arrays.fill(positive, 0);\n        Arrays.fill(negative, 0);\n        for (int i=n-1; i>=0; i--) {\n            if (nums[i] < 0) {\n                positive[i] = positive[i+1];\n                negative[i] = negative[i+1]+1;\n            }\n            else if (nums[i] > 0) {\n                positive[i] = positive[i+1]+1;\n                negative[i] = negative[i+1];\n            }\n            if (negative[i] % 2 == 0)\n                result = Math.max(result, positive[i] + negative[i]);\n        }\n        return result;\n    }\n}\n```
['Dynamic Programming', 'Java']