C++ every solution I could think of
dp of O(N^2) time and O(N^2) space complexity ( ofcourse gives TLE :( )\n\n#define ll long long int\nclass Solution {\npublic:\n    int getMaxLen(vector<int>& n
1. **dp** of O(N^2) time and O(N^2) space complexity ( ofcourse gives TLE :( )\n```\n#define ll long long int\nclass Solution {\npublic:\n    int getMaxLen(vector<int>& nums) {\n        ll len, i, j, n=nums.size(), ans=0;\n        vector<vector<ll>> dp(n, vector<ll>(n));\n        for(len=1; len<=n; len++){\n            for(i=0; i<=n-len; i++){\n                j=i+len-1;\n                if(len==1)\n                    dp[i][j]=(nums[i]>0 ? 1 : (!nums[i] ? -1 : 0));\n                else if(len==2)\n                    dp[i][j]=((ll)nums[i]*(ll)nums[j]>0 ? 2 :(!((ll)nums[i]*(ll)nums[j])? -1 : 0));\n                else{\n                    if(nums[i]>0 && nums[j]>0)\n                        dp[i][j]=(dp[i+1][j-1]>0 ? 2+dp[i+1][j-1] : (dp[i+1][j-1]<0 ? -1 : 0));\n                    else if(nums[i]<0 && nums[j]<0)\n                        dp[i][j]=(dp[i+1][j-1]>0 ? 2+dp[i+1][j-1] : (dp[i+1][j-1]<0 ? -1 : 0));\n                    else if(nums[i] && nums[j] && (nums[i]<0 || nums[j]<0))\n                        dp[i][j]=(!dp[i+1][j-1] ? j-i+1 : (dp[i+1][j-1]<0 ? -1 : 0));\n                    else\n                        dp[i][j]=-1;\n                }\n                ans=max(ans, dp[i][j]);\n            }\n        }\n        return ans;\n    }\n};\n```\n\n2. **dp** of O(N) time and O(N) space complexity\n```\n#define ll long long int\nclass Solution {\npublic:\n    int getMaxLen(vector<int>& nums) {\n        ll i, n=nums.size(), ans=0;\n        vector<ll> pos(n), neg(n);\n        pos[0]=nums[0]>0 ? 1 : 0;\n        neg[0]=nums[0]<0 ? 1 : 0;\n        ans=pos[0];\n        for(i=1; i<n; i++){\n            if(nums[i]>0){\n                pos[i]=1+pos[i-1];\n                neg[i]=neg[i-1]>0 ? 1+neg[i-1]:0;\n            }\n            else if(nums[i]<0){\n                pos[i]=neg[i-1]>0 ? 1+neg[i-1] : 0;\n                neg[i]=1+pos[i-1];\n            }\n            ans=max(ans, pos[i]);\n        }\n        return ans;\n    }\n};\n```\n\n3. **dp** of O(N) time and O(1) space complexity\n```\n#define ll long long int\nclass Solution {\npublic:\n    int getMaxLen(vector<int>& nums) {\n        ll i, n=nums.size(), ans=0, pos, neg;\n        pos=nums[0]>0 ? 1 : 0;\n        neg=nums[0]<0 ? 1 : 0;\n        ans=pos;\n        for(i=1; i<n; i++){\n            if(nums[i]>0){\n                pos=1+pos;\n                neg=neg>0 ? 1+neg :0;\n            }\n            else if(nums[i]<0){\n                int temp=pos;\n                pos=neg>0 ? 1+neg : 0;\n                neg=1+temp;\n            }\n            else\n                pos=neg=0;\n            \n            ans=max(ans, pos);\n        }\n        return ans;\n    }\n};\n```\n4. **Sliding window** uing suffix of O(N) time and O(N) space complexity (gives integer overflow because of multiplication :( )\n```\n#define ll long long int\nclass Solution {\npublic:\n    int getMaxLen(vector<int>& nums) {\n        ll start=0, end=0, prod=1, i, n=nums.size(), ans=0;\n        vector<int> suff(n);\n        for(i=n-1; i>=0; i--){\n            if(!nums[i])\n                continue;\n            suff[i]=nums[i]<0 ? suff[min(i+1, n-1)]+1 : suff[min(i+1, n-1)];\n        }\n        while(end<n){\n            while(end<n){\n                if(nums[end]>0)\n                    prod=prod*nums[end++];\n                else if(nums[end]<0){\n                    if((prod>0 && suff[end]>1) || (prod<0 && suff[end]>=1))\n                        prod=prod*nums[end++];\n                    else\n                        break;\n                }\n                else \n                    break;\n            }\n            \n            ans=max(ans, end-start);\n            if(end<n && (!nums[end] || suff[start]<2)){\n                end++;\n                start=end;\n                prod=1;\n                continue;\n            }\n            while(end<n && start<end && prod>0){\n                if(suff[start]>1)\n                    prod/=nums[start++];\n            }\n        }\n        return max(ans, end-start);\n    }\n};\n```\n\n4. **Sliding window uing suffix** of O(N) time and O(N) space complexity *(doesn\'t uses multiplication)*\n```\n#define ll long long int\nclass Solution {\npublic:\n    int getMaxLen(vector<int>& nums) {\n        ll start=0, end=0, prod=1, i, n=nums.size(), ans=0;\n        vector<int> suff(n);\n        for(i=n-1; i>=0; i--){\n            if(!nums[i])\n                continue;\n            suff[i]=nums[i]<0 ? suff[min(i+1, n-1)]+1 : suff[min(i+1, n-1)];\n        }\n        while(end<n){\n            while(end<n){\n                if(nums[end]>0)\n                    end++;\n                else if(nums[end]<0){\n                    if(suff[end]>1 || (suff[start]>suff[end] && !((suff[start]-suff[end]+1)%2)))\n                        end++;\n                    else\n                        break;\n                }\n                else \n                    break;\n            }\n            ans=max(ans, end-start);\n            if(end<n && (!nums[end] || suff[start]==suff[end])){\n                end++;\n                start=end;\n                continue;\n            }\n            while(end<n && start<end){\n                if((suff[start]-suff[end]+1)%2)\n                    start++;\n                else\n                    break;\n            }\n        }\n        return max(ans, end-start);\n    }\n};\n```
['Dynamic Programming', 'Sliding Window', 'C++']