Maximum Product Subarray

Medium

Given an integer array nums, return the largest product of any contiguous subarray.

Example 1

maxProduct()
Input
nums = [2,3,-2,4]
Output
6

Why

[2,3]

Example 2

maxProduct()
Input
nums = [-2,0,-1]
Output
0
Constraints
1 <= nums.length <= 2 * 10^4
-10 <= nums[i] <= 10
The answer fits in a 32-bit integer.

Topics

ArraysDynamic Programming

Implement maxProduct in the editor and return the answer — printing it is never graded.