<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:
        def splitOnZeros():
            res = []
            curr = []
            for num in nums:
                if num == 0:
                    res.append(curr)
                    res.append([0])
                    curr = []
                else:
                    curr.append(num)
            if len(curr) != 0:
                res.append(curr)
            return res

        def partial_products(lst):
            products = [1]
            for e in lst:
                products.append(products[-1] * e)
            return products

        def find_first_and_last_neg(lst):
            first_neg = -1
            last_neg = -1
            for idx, num in enumerate(lst):
                if num < 0:
                    last_neg = idx
                    if first_neg == -1:
                        first_neg = idx
            return first_neg, last_neg

        def solveNoZeros(numsNoZ):
            if len(numsNoZ) == 0:
                return 0
            if len(numsNoZ) == 1:
                return numsNoZ[0]

            pp = partial_products(numsNoZ)
            p  = pp[-1]
            if p > 0:
                return p

            first_neg, last_neg = find_first_and_last_neg(numsNoZ)
            return max(p // pp[first_neg + 1], pp[last_neg])
        return max(map(solveNoZeros, splitOnZeros()))

        
18000