Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product.
Example 1:
Input: [2,3,-2,4]
Output: 6
Explanation: [2,3] has the largest product 6.
Example 2:
Input: [-2,0,-1]
Output: 0
Explanation: The result cannot be 2, because [-2,-1] is not a subarray.
class Solution:
     def maxProduct(self, nums):
         """
         :type nums: List[int]
         :rtype: int
         """
         n=len(nums)		
         if n==0: return 0
         if n==1: return nums[0]
         ans=nums[0]
         l=0
         r=n-1 
         prod=1
 
         i=0
         while i<n:
             if nums[i]==0:
                 zero_idx=i
                 return max(self.maxProduct(nums[(zero_idx+1):]), max(0,self.maxProduct(nums[0:zero_idx])))
             else:
                 prod=prod*nums[i]
                 i=i+1
 		
 
         if prod>0: return prod
         prod_right=prod
         max_prod_right=prod
 		
         prod_left=prod
         max_prod_left=prod
 		
         if prod<0:
             #print(max_prod_right)           
             while 0<=r:
                 prod_right=prod_right//nums[r]
                 r=r-1
                 if prod_right>max_prod_right:
                     if prod_right>0:
                         max_prod_right=prod_right
                         break
                     else:
                         max_prod_right=prod_right
 						
 		    
             print(max_prod_left)
             while l<n:
                 prod_left=prod_left//nums[l]
                 l=l+1
                 #print(l, prod_left,"----", nums[l], nums[l:])
                 if prod_left>max_prod_left:
                     if prod_left>0:
                         max_prod_left=prod_left
                         break
                 else:
                     max_prod_left=prod_left
 
         #print(max_prod_left, max_prod_right)			
         return max(max_prod_left, max_prod_right)
 		

class Solution:
     def maxProduct(self, nums):
         """
         :type nums: List[int]
         :rtype: int
         """
         n=len(nums)		
         if n==0: return 0
         if n==1: return nums[0]
         ans=nums[0]
         l=0
         r=n-1 
         prod=1
 
         i=0
         while i<n:
             if nums[i]==0:
                 zero_idx=i
                 return max(self.maxProduct(nums[(zero_idx+1):]), max(0,self.maxProduct(nums[0:zero_idx])))
             else:
                 prod=prod*nums[i]
                 i=i+1
 		
 
         if prod>0: return prod
         prod_right=prod
         max_prod_right=prod
 		
         prod_left=prod
         max_prod_left=prod
 		
         if prod<0:
             #print(max_prod_right)           
             while 0<=r:
                 prod_right=prod_right//nums[r]
                 r=r-1
                 if prod_right>max_prod_right:
                     if prod_right>0:
                         max_prod_right=prod_right
                         break
                     else:
                         max_prod_right=prod_right
 						
 		    
             print(max_prod_left)
             while l<n:
                 prod_left=prod_left//nums[l]
                 l=l+1
                 #print(l, prod_left,"----", nums[l], nums[l:])
                 if prod_left>max_prod_left:
                     if prod_left>0:
                         max_prod_left=prod_left
                         break
                 else:
                     max_prod_left=prod_left
 
         #print(max_prod_left, max_prod_right)			
         return max(max_prod_left, max_prod_right)
 		
