Maximum Product Subarray With One Deletion

Given an integer array nums, return the maximum product of a subarray after deleting at most one element from that subarray. Pattern focus: Max product subarray. This variant tests whether you can adapt the running-product recurrence to allow one skip.

Input Format

nums = integer array

Output Format

maximum product after deleting at most one element

Constraints

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

Examples

Example 1:

Input:

nums = [1,-2,-3,4]

Output:

24

Explanation:

Removing nothing already gives the best product.

Example 2:

Input:

nums = [-1,-2,-3,0]

Output:

6

Explanation:

Deleting one negative element from [-1,-2,-3] gives product 6.

Loading...
Maximum Product Subarray With One Deletion