Maximum Product Subarray II

Given an integer array nums, return the largest product of any non-empty contiguous subarray, with stronger stress on sign changes and zeros. Pattern focus: Max product subarray. The recurrence must keep the best positive and most negative running products simultaneously.

Input Format

nums = integer array

Output Format

maximum product of any contiguous subarray

Constraints

  • 1 <= nums.length <= 10^5; -10 <= nums[i] <= 10

Examples

Example 1:

Input:

nums = [-1,-3,-10,0,60]

Output:

60

Explanation:

The single element 60 is the best product.

Example 2:

Input:

nums = [6,-3,-10,0,2]

Output:

180

Explanation:

The subarray [6,-3,-10] has product 180.

Loading...
Maximum Product Subarray II - Dp 1d DSA Problem