Blind 75
Maximum Product Subarray (medium)
Problem Statement
Given an integer array, find the contiguous subarray (at least one number in it) that has the maximum product. Return this maximum product.
Examples
-
- Input: [2,3,-2,4]
- Expected Output: 6
- Justification: The subarray [2,3] has the maximum product of 6.
-
- Input: [-2,0,-1]
- Expected Output: 0
- Justification: The subarray [0] has the maximum product of 0.
-
- Input: [-2,3,2,-4]
- Expected Output: 48
- Justification: The subarray [-2,3,2,-4] has the maximum product of 48.
Constraints:
- 1 <= nums.length <= 2*10<sup>4</sup>
-10 <= nums[i] <= 10
- The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.
Try it yourself
Try solving this question here:
Python3
Python3