# Maximum Product Subarray

`Input: nums = [2,3,-2,4]Output: 6Explanation: [2,3] has the largest product 6.`
`Input: nums = [-2,0,-1]Output: 0Explanation: The result cannot be 2, because [-2,-1] is not a subarray.`
`    def maxProduct(self, nums: List[int]) -> int:        max_=-1*float('inf')        for i in range(len(nums)):            prod=1            for j in range(i,len(nums)):                prod*=nums[j]                if(max_<prod):                    max_=prod        return(max_)`
`def maxProduct(self, nums):        global_,max_,min_=nums[0],nums[0],nums[0]        i=1        while(i<len(nums)):            prev_max=max_            max_=max(nums[i],max_*nums[i],min_*nums[i])            min_=min(nums[i],prev_max*nums[i],min_*nums[i])            global_=max(global_,max_)            i+=1        return global_`
`n=len(nums)left,right=1,1global_max=-1*float('inf')for i in range(n):  if(left==0):    left=1  if(right==0):    right=1  left*=nums[i]  right=nums[n-1-i]global_max=max(global_max,left,right)return global_max`

--

--

--

## More from Dhanarajappu

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.

Love podcasts or audiobooks? Learn on the go with our new app.

## Dhanarajappu

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.