#1856

Maximum Subarray Min-Product

expert · 1010 · lc medium +32 · verified · 40.1% accepted · 1,555 likes · top 19%

Description

The min-product of an array is its minimum value multiplied by the sum of all its elements.

Given an integer array nums, find the maximum min-product across all non-empty subarrays. Return the result modulo 109 + 7. Compute the maximum before taking the modulo.

Example 1:

Input: nums = [1,2,3,2]
Output: 14
Explanation: The maximum min-product is achieved with the subarray [2,3,2] (minimum value is 2).
2 * (2+3+2) = 2 * 7 = 14.

Example 2:

Input: nums = [2,3,3,1,2]
Output: 18
Explanation: The maximum min-product is achieved with the subarray [3,3] (minimum value is 3).
3 * (3+3) = 3 * 6 = 18.

Example 3:

Input: nums = [3,1,5,6,4,2]
Output: 60
Explanation: The maximum min-product is achieved with the subarray [5,6,4] (minimum value is 4).
4 * (5+6+4) = 4 * 15 = 60.

Code

1
2
3