Dynamic Programming
LC #152Medium
Maximum Product Subarray
Dynamic Programming
AmazonLinkedInGoogleMetaProblem
Find the contiguous subarray with the largest product. The array may contain negative numbers and zeros.
arraydynamic-programming
Constraints
- ›1 ≤ nums.length ≤ 2×10⁴
- ›-10 ≤ nums[i] ≤ 10
- ›Product fits in a 32-bit integer
Example
Input
nums = [2, 3, -2, 4]Output
6Why
[2,3] has the largest product = 6