O(n) space and time C++ solution
```\nclass Solution {\npublic:\n    int getMaxLen(vector& nums) {\n        \n        int n=nums.size();\n        vector> dp(2,vector(n+1,0));\n        \n       
```\nclass Solution {\npublic:\n    int getMaxLen(vector<int>& nums) {\n        \n        int n=nums.size();\n        vector<vector<int>> dp(2,vector<int>(n+1,0));\n        \n        dp[0][0]=dp[1][0]=0;\n        int maxlen=0;\n        \n        for(int i=1;i<=n;i++)\n        {\n            if(nums[i-1]>0)\n            {\n                dp[0][i]=dp[0][i-1]+1;\n                dp[1][i]=(dp[1][i-1]==0)? 0 : dp[1][i-1]+1;\n            }\n            else if(nums[i-1]<0)\n            {\n                dp[0][i]=(dp[1][i-1]==0)? 0 : dp[1][i-1]+1;\n                dp[1][i]=dp[0][i-1]+1;\n            }\n            maxlen=max(maxlen,dp[0][i]);\n        }\n        \n        return maxlen;\n    }\n};\n\nPlease Upvote if found helpful
['Dynamic Programming', 'C', 'C++']