Easy to understand | Java | 1ms
Here we need to keep track of positive sum whenever we found 0 mark reset max posivitve subarray  count and max negative subarray count to 0\nExample:\n[2,3,4, 
Here we need to keep track of positive sum whenever we found 0 mark reset max posivitve subarray  count and max negative subarray count to 0\n**Example:**\n[2,3,4, -2] => ans will be 3 [2,3,4]\nupto 4(index2) the positive count will be 3\nwhen we encounter -2,  **positive count** will become **0**, now **negative** count will becomes **postive length+1**\nupto now pos holds [2,3,4] now multiply with negative number entire product becomes negative [2,3,4, -2] = -48, so negative count becomes positive count+1\n\n**SUppose the above array holds anther number -4 at end**\n**[2,3,4, -2, -4]**  => ans becomes 5\nwe know upto -2 The pos count =0, negcount = 4\nfor -4, now pos count becomes **neg +1** because entire array make product positive\nneg count becomes 1\n\n\n```\nclass Solution {\n    public int getMaxLen(int[] nums) {\n        int pos = 0, neg = 0, result= 0, N = nums.length;\n        for(int i=0; i<N; i++){\n            if(nums[i]==0){\n                pos=0;\n                neg=0;\n            } else if(nums[i] > 0){\n                pos= pos+1;\n                neg = neg ==0 ? 0 : neg+1;\n                \n            } else{\n                int temp = pos;\n                pos = neg ==0  ? 0 : neg+1; \n                neg = temp+1;\n            }\n            result = Math.max(pos, result);\n        }\n        \n        return result;\n    }\n}\n```\n\nTime Complexity: **O(N)**\nSpace Complexity: **O(1)**\n\nIf you have any **doubts**, feel **free to ask**...\nIf you understand the **concept**. Dont Forget to **upvote**\n
['Java']