# Maximum Product Subarray (Leetcode 152)

Problem Link: <https://leetcode.com/problems/maximum-product-subarray/>

```python
class Solution:
    def maxProduct(self, nums: List[int]) -> int:

        n=len(nums)
        curr_max_p=nums[0]
        curr_min_p=nums[0]
        ans=nums[0]
        prev_min_p=nums[0]
        prev_max_p=nums[0]
        for i in range(1,n):
            curr_min_p=min(nums[i],prev_min_p*nums[i],prev_max_p*nums[i])
            curr_max_p=max(nums[i],prev_min_p*nums[i],prev_max_p*nums[i])
            ans=max(ans,curr_max_p)
            prev_min_p=curr_min_p
            prev_max_p=curr_max_p
        return ans
```
