Super simple to understand | Explained | DP O(N) time | O(1) Space
This task is very similar to 152. Maximum Product Subarray, but even simplier.\n\nThe main idea is that we don\'t need to know the real product, enough to track
This task is very similar to [152. Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray), but even simplier.\n\nThe main idea is that we don\'t need to know the real product, enough to track only its sign: is it positive or negative.\nThe positive product could happen in two cases:\n1. All numbers in the subarray are positive.\n2. Subarray contains an even count of negative numbers.\n\n**And subarray should not contain any zeroes**. Even one will turn a product of the whole subarray into zero.\nThat\'s why every zero resets our pointers to most left positive and negative products.\n\nThe algorithm is built around the following ideas:\n1. No matter what, if a current product is positive, the longest possible positive sub array will contain all numbers to the start of array OR previous zero if any.\n2. If the current product is negative, the longest possible positive sub-array will contain all numbers to the most left negative number from the current one if any.\n\n**Time complexity:** `O(N) where N is a length of nums array since we process every number exactly once`\n**Space complexity:** `O(1) since every time the only fixed number of variables with fixed allocated`\n\n<iframe src="https://leetcode.com/playground/455Xa8Qf/shared" frameBorder="0" width="100%" height="800"></iframe>\n\n**Thank you for reading this!** =)
['Dynamic Programming', 'C', 'Python', 'Go', 'Python3']