<p>Given an integer array <code>nums</code>, find a <span data-keyword="subarray-nonempty">subarray</span> that has the largest product, and return <em>the product</em>.</p>

<p>The test cases are generated so that the answer will fit in a <strong>32-bit</strong> integer.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [2,3,-2,4]
<strong>Output:</strong> 6
<strong>Explanation:</strong> [2,3] has the largest product 6.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [-2,0,-1]
<strong>Output:</strong> 0
<strong>Explanation:</strong> The result cannot be 2, because [-2,-1] is not a subarray.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 2 * 10<sup>4</sup></code></li>
	<li><code>-10 &lt;= nums[i] &lt;= 10</code></li>
	<li>The product of any subarray of <code>nums</code> is <strong>guaranteed</strong> to fit in a <strong>32-bit</strong> integer.</li>
</ul>

class Solution:
    def maxProduct(self, nums: List[int]) -> int:
        n = len(nums)
        if n == 1:
            return nums[0]
        arr, tmp = [], []

        for i in range(n):
            if nums[i] == 0:
                arr.append(tmp)
                tmp = []
            else:
                tmp.append(nums[i])
        arr.append(tmp)
        print(arr)
        ans = 0
        for ar in arr:
            ans = max(ans, self.find(ar))
        return ans

    def find(self, arr):
        n = len(arr)
        if n == 0:
            return -float("inf")
        if n == 1:
            return arr[0]
        neg = []
        for i in range(len(arr)):
            if arr[i] < 0:
                neg.append(i)
        
        if len(neg) % 2 == 0:
            return self.prod(arr)
        first = neg[0]
        last = neg[-1]
        if first == last:
            a = self.prod(arr[first + 1:])
            b = self.prod(arr[:first])
            return max(a,b)
        else:
            a = self.prod(arr[:first])
            b = self.prod(arr[first + 1:])
            c = self.prod(arr[last+1:])
            d = self.prod(arr[:last])
            return max(a,b,c,d)
            
    def prod(self, arr):
        n = len(arr)
        if n == 0:
            return -float("inf")
        if n == 1:
            return arr[0]
        ans = arr[0]
        for i in range(1,n):
            ans = ans * arr[i]
        return ans
17400