Faster || Easy To Understand || C++ Code
Time Complexity : O(N)\n Space Complexity : O(1)*\n\n\nclass Solution {\npublic:\n    int getMaxLen(vector<int>& nums) {\n        \n        int n = nums.size();
* ***Time Complexity : O(N)***\n* ***Space Complexity : O(1)***\n\n```\nclass Solution {\npublic:\n    int getMaxLen(vector<int>& nums) {\n        \n        int n = nums.size();\n        \n        int longest = 0;\n        \n        int i = 0;\n        \n        while(i < n)\n        {\n            int start = i;\n            \n            while(start < n && nums[start] == 0)\n            {\n                start++;\n            }\n            \n            int end = start;\n            \n            int count_neg = 0;\n            \n            int start_neg = -1;\n            \n            int end_neg = -1;\n            \n            while(end < n && nums[end] != 0)\n            {\n                if(nums[end] < 0)\n                {\n                    count_neg++;\n                    \n                    if(start_neg == -1)\n                    {\n                        start_neg = end;\n                    }\n                    \n                    end_neg = end;\n                }\n                \n                end++;\n            }\n            \n            if(count_neg % 2 == 0)\n            {\n                longest = max(longest, end - start);\n            }\n            \n            else\n            {\n                if(start_neg != -1)\n                {\n                    longest = max(longest, end - start_neg - 1);\n                }\n                \n                if(end_neg != -1)\n                {\n                    longest = max(longest, end_neg - start);\n                }\n            }\n            \n            i = end + 1;\n        }\n        \n        return longest;\n    }\n};\n```
['Greedy', 'C']