Maximum Subarray Min-Product - Problem
The min-product of an array is equal to the minimum value in the array multiplied by the array's sum.
For example, the array [3,2,5] (minimum value is 2) has a min-product of 2 * (3+2+5) = 2 * 10 = 20.
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 109 + 7.
Note that the min-product should be maximized before performing the modulo operation. Testcases 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.
Input & Output
Example 1 — Basic Case
$
Input:
nums = [1,2,3,2]
›
Output:
14
💡 Note:
The subarray [2,3,2] has minimum 2 and sum 7, giving min-product = 2 × 7 = 14, which is maximum among all subarrays.
Example 2 — Single Element
$
Input:
nums = [2,3,3,1,2]
›
Output:
18
💡 Note:
The subarray [2,3,3] has minimum 2 and sum 8, giving min-product = 2 × 8 = 16. But [3,3] has min-product = 3 × 6 = 18.
Example 3 — Large Numbers
$
Input:
nums = [3,1,5,6,4,2]
›
Output:
60
💡 Note:
The subarray [5,6,4] has minimum 4 and sum 15, giving min-product = 4 × 15 = 60, which is the maximum.
Constraints
- 1 ≤ nums.length ≤ 105
- 1 ≤ nums[i] ≤ 107
Visualization
Tap to expand
Understanding the Visualization
1
Input Array
Given array [1,2,3,2] with different elements
2
Find Subarrays
Consider all possible contiguous subarrays
3
Calculate Min-Products
For each subarray: min-product = minimum × sum
Key Takeaway
🎯 Key Insight: For each element as the minimum, find the largest possible subarray containing it using monotonic stack
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code