[Python] Clean DP Solution with Video Explanation
Video with clear visualization and explanation: \nhttps://youtu.be/FqpfLr76a1k\n\nIntuition: Dynamic Programming\n\nCode\nInspired by\nhttps://leetcode.com/prob
Video with clear visualization and explanation: \nhttps://youtu.be/FqpfLr76a1k\n\n**Intuition:** Dynamic Programming\n\n**Code**\nInspired by\nhttps://leetcode.com/problems/maximum-length-of-subarray-with-positive-product/discuss/819329/Python3GoJava-Dynamic-Programming-O(N)-time\n\n```\nclass Solution:\n    def getMaxLen(self, nums: List[int]) -> int:\n        n = len(nums)\n        \n        pos, neg = [0]*n, [0]*n\n        if nums[0] > 0: pos[0] = 1\n        if nums[0] < 0: neg[0] = 1\n        \n        res = pos[0]\n        \n        for i in range(1, n):\n            #if nums[i] == 0, pos[i] won\'t be updated\n            if nums[i] > 0:\n                pos[i] = 1+pos[i-1]\n                neg[i] = 1+neg[i-1] if neg[i-1] > 0 else 0\n            elif nums[i] < 0:\n                pos[i] = 1+neg[i-1] if neg[i-1] > 0 else 0\n                neg[i] = 1+pos[i-1]\n            res = max(res, pos[i])\n            \n        return res\n```\n\nTime Complexity: O(n)\nSpace Complexity: O(n)(Can be reduced to O(1) if reduce dp array to var)\n\nFeel free to subscribe to my channel. More LeetCoding videos coming up!\n\t
['Dynamic Programming', 'Python']