Maximum Product Subarray

00:00
MediumArrayDynamic Programming
AmazonFlipkart

Find the contiguous subarray with the largest product. Array can contain negative numbers and zeros.

Examples

Input → [2,3,-2,4]
Output → 6
Explanation:

[2,3]

Input → [-2,0,-1]
Output → 0
Input → [-2,3,-4]
Output → 24
Explanation:

entire array: -2×3×-4=24