LeetCode 1856, Medium. Topics: Array, Stack, Monotonic Stack, Prefix Sum, Cartesian Tree. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 22 parametrized pytest cases, and a playground notebook:
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 10^9 + 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.
Examples
Constraints
1 <= nums.length <= 10^5
1 <= nums[i] <= 10^7
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
NeetCode All. Last modified on September 7, 2026