Medium
Quiz
#152 Maximum Product Subarray
APPROACH
Given an integer array nums, find the contiguous subarray with the largest product and return that product.
The answer is guaranteed to fit in a 32-bit integer.
A subarray consisting of a single element has a product equal to that element's value.
Example 1:
Input: nums = [2,3,-2,4]
Output: 6
Explanation: [2,3] has the largest product 6.
Example 2:
Input: nums = [-2,0,-1]
Output: 0
Explanation: The result cannot be 2, because [-2,-1] is not a subarray.
1 of 4
1:00
What is the optimal approach for this problem?