[C++] Easy Solution O(n). Commented. Tracking with Longest Subarray ending at current index.
\nclass Solution {\npublic:\n    int getMaxLen(vector<int>& nums) {\n        /*  *storing the longest positive subarray ended at current index starting from ind
```\nclass Solution {\npublic:\n    int getMaxLen(vector<int>& nums) {\n        /*  *storing the longest positive subarray ended at current index starting from index p.\n            *storing the longest negatice subarray ended at current index starting from index n.\n            *storing max length positive subarray\n        */\n        ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);\n        int p = -1, n = -1;\n        int ans = 0;\n        for(int i = 0; i < nums.size(); ++i) {\n            \n            if(nums[i] > 0) {\n                // if p == -1 means that no positive subarrays ended at this index. so start p with this index.\n                if(p == -1) p = i;\n            } else if(nums[i] < 0) {\n\t\t\t   // storing previous p\n                int tmp = p;\n                // negative numbers will change the sign so longest negative subarrays ending at this index will become longest positive subarrays ending at this index\n                p = n;\n                // if n == -1 means that no negative subarrays ended at this index. so start p with this index.\n                if(tmp == -1) n = i;\n                \n                else n = tmp;\n            } else {\n                // if nums[i] == 0, p and n will be reset\n                p = -1, n = -1;\n            }\n            \n\t\t\t// If there exists a  Longest Subarray ending at current index we need to update our ans with current_index - starting + 1\n            if(p != -1)\n                ans = max(ans, i - p + 1);\n        }\n        return ans;\n    }\n};\n```
['Two Pointers', 'Greedy', 'C']