Java | 100% faster | O(N) time and O(1) space | With explanation
\nclass Solution {\n    public int getMaxLen(int[] nums) {\n        // llp = Length of the longest positive subarray\n        int llp = 0;\n        // lln = len
```\nclass Solution {\n    public int getMaxLen(int[] nums) {\n        // llp = Length of the longest positive subarray\n        int llp = 0;\n        // lln = length of the longest negative subarray\n        int lln = 0;\n        // max length of the positive subarray\n        int max = 0;\n        for (int i = 0; i < nums.length; i++) {\n            // Reset the lengths upon encountering a zero\n            if (nums[i] == 0) {\n                llp = lln = 0;\n            } else if (nums[i] > 0) {\n                // Upon encountering a positive value, increase the length of the positive subarray till now by one\n                llp++;\n                // Increase the length of the negative subarray only if there\'s a negative product. \n                // If there are no negative numbers before the current number or if the (i-1)th number is zero, we should not increase this value.\n                if (lln > 0) lln++;\n            } else {\n                // Upon encountering a negative value, the lengths of the positive and negative subarrays need to be swapped.\n                int temp = llp;\n                // If there are no negative numbers before the current number, then llp should be zero. \n                // so we need an extra check to ensure that\n                llp = (lln > 0 ? lln + 1 : 0);\n                lln = temp + 1;\n            }\n            max = Math.max(max, llp);\n        }\n        return max;\n    }\n}\n```
['Dynamic Programming', 'Java']