1213. Maximum Product Subarray

MediumDynamic ProgrammingPartition DP

Given an array nums, return the largest product of any non-empty contiguous subarray. The input is JSON {nums}.

Input: JSON {nums}.

Output: Integer — the maximum subarray product.

Examples

Example 1
Input: {"nums":[2,3,-2,4]}
Output: 6
Explanation: [2,3] gives 6.
Example 2
Input: {"nums":[-2,0,-1]}
Output: 0
Explanation: Best is 0.
Example 3
Input: {"nums":[0]}
Output: 0
Explanation: Single element.

Constraints

Asked by

AdobeSwiggyAmazonBloombergGoogleInfosys
Solve this problem in the editor →