Maximum Subarray Min-Product

The min-product of an array is equal to the minimum value in the array multiplied by the array's sum.

Given an array of integers nums, return the maximum min-product of any non-empty subarray of nums. Since the answer may be large, return it modulo 10^9 + 7.

Note that the min-product should be maximized before performing the modulo operation. Test cases are generated such that the maximum min-product without modulo will fit in a 64-bit signed integer.

A subarray is a contiguous part of an array.

Example 1
Inputnums = [1,2,3,2]
Output14
The maximum min-product is achieved with the subarray [2, 3, 2], whose minimum value is 2 and sum is 7, giving 2 * 7 = 14.
Example 2
Inputnums = [2,3,3,1,2]
Output18
The maximum min-product is achieved with the subarray [3, 3], whose minimum value is 3 and sum is 6, giving 3 * 6 = 18.

Constraints

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

Asked at 3 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate