Back to DSA
Maximum Product Subarray
hardGiven an integer array, identify the contiguous subarray whose product of elements is the largest and return that product.
Examples
Example 1:
Input:
nums = [3,-1,4,-2]Output:
24Explanation: The entire array has product 3*(-1)*4*(-2) = 24.
Example 2:
Input:
nums = [-3,0,2,-5]Output:
2Explanation: The single element [2] gives the maximum product.
Hints
1234567