Maximum Product Subarray
Problem statement
Given an integer array nums, return the largest product of any non-empty contiguous subarray.
Function
maxProduct(nums: int[]) → intExamples
Example 1
nums = [2,3,-2,4]return = 6The contiguous subarray [2,3] has product 6.
Example 2
nums = [-2,0,-1]return = 0The two negative values are separated by 0, so they cannot belong to the same contiguous subarray.
Example 3
nums = [-2,3,-4]return = 24The entire array has product 24.
Constraints
1 <= nums.length <= 20000.-10 <= nums[i] <= 10.- The product of every contiguous subarray fits in a signed 32-bit integer.