SIMPLE DP SOLUTION | C++ | Time Complexity: O(n) SPACE : O(1)
```\n    int getMaxLen(vector& nums) {\n        \n        int i,j,n=nums.size(),oddind=-1,eveind=-1,maxi=0;\n        int dp[n][2],ct=0;\n      \n        if(nums
```\n    int getMaxLen(vector<int>& nums) {\n        \n        int i,j,n=nums.size(),oddind=-1,eveind=-1,maxi=0;\n        int dp[n][2],ct=0;\n      \n        if(nums[0] ==0)\n        {\n            dp[0][0] = 0;\n            dp[0][1] = 0;\n        }\n        if(nums[0] >0)\n        {\n            dp[0][0] = 1;\n            dp[0][1] = 0;\n        }\n        if(nums[0] <0)\n        {\n            dp[0][0] = 0;\n            dp[0][1] = 1;\n            ct++;\n        }\n        maxi = max(maxi,dp[0][0]);\n        for(i=1;i<n;i++)\n        {\n            if(nums[i]>0)\n            {\n                dp[i][0] = dp[i-1][0] + 1;\n                dp[i][1] = dp[i-1][1] + 1;\n                maxi = max(maxi,dp[i][0]);\n                continue;\n            }\n            if(nums[i]<0)\n            {\n                ct++;\n                if(ct==1)\n                {\n                    dp[i][0] = 0;\n                    dp[i][1] = dp[i-1][0] + 1;\n                    continue;\n                }\n                else{\n                    dp[i][0] = dp[i-1][1] +1;\n                    dp[i][1] = dp[i-1][0] +1;\n                    maxi = max(maxi,dp[i][0]);\n                    continue;\n                }\n            }\n            if(nums[i]==0)\n            {\n                ct=0;\n                dp[i][0] = 0;\n                dp[i][1] = 0;\n            }\n            \n        }\n        return maxi;\n        \n    }
['Dynamic Programming']