C++| DP O(n)
\nclass Solution {\npublic:\n    int getMaxLen(vector<int>& nums) {\n        vector<vector<int>> dp(nums.size(),vector<int>(2,0)); //stores maximum length of +v
```\nclass Solution {\npublic:\n    int getMaxLen(vector<int>& nums) {\n        vector<vector<int>> dp(nums.size(),vector<int>(2,0)); //stores maximum length of +ve[0] and -ve[1] seq including current index\n        \n        if(nums[0]>0) dp[0][0]++;\n        else if(nums[0]<0) dp[0][1]++;\n        \n        int re = dp[0][0];\n        for(int i = 1; i<nums.size();++i){\n            if(nums[i]!=0){\n                if(nums[i]>0){\n                    dp[i][0] = 1+dp[i-1][0];\n                    if(dp[i-1][1])\n                      dp[i][1] = 1+dp[i-1][1];\n                }\n                else{\n                    if(dp[i-1][1]) dp[i][0] = dp[i-1][1]+1;\n                    dp[i][1] = dp[i-1][0]+1;\n                }\n            }\n            re = max(re,dp[i][0]);\n        }\n        return re;\n    }\n};\n```\nupvote if it helps
['Dynamic Programming', 'C']