Maximum Product Subarray
Given an integer array nums, find a subarray that has the largest product, and return the product.

30:00

Maximum Product Subarray
medium
Topics
Companies

Given an integer array nums, find a subarray that has the largest product, and return the product.

Example 1:
Input: [2,3,-2,4]
Output: 6
Constraints:
  • 1nums.length2×1041 \leq \text{nums.length} \leq 2 \times 10^4

  • 10nums[i]10-10 \leq \text{nums}[i] \leq 10

  • The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.

Input
arr =[2,3,-2,4]

2

3

-2

4

Current Sum
1
Max Sum
4
Variables
VariableValue
res4
curMin1
curMax1
DepthFunction Call
Stack empty
0/17