1856. Maximum Subarray Min-Product Medium

@problem@discussion
#Array#Stack#Monotonic Stack#Prefix Sum



1/**
2 * [1856] Maximum Subarray Min-Product
3 *
4 * The min-product of an array is equal to the minimum value in the array multiplied by the array's sum.
5 * 
6 * 	For example, the array [3,2,5] (minimum value is 2) has a min-product of 2 * (3+2+5) = 2 * 10 = 20.
7 * 
8 * 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.
9 * 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.
10 * A subarray is a contiguous part of an array.
11 *  
12 * Example 1:
13 * 
14 * Input: nums = [1,<u>2,3,2</u>]
15 * Output: 14
16 * Explanation: The maximum min-product is achieved with the subarray [2,3,2] (minimum value is 2).
17 * 2 * (2+3+2) = 2 * 7 = 14.
18 * 
19 * Example 2:
20 * 
21 * Input: nums = [2,<u>3,3</u>,1,2]
22 * Output: 18
23 * Explanation: The maximum min-product is achieved with the subarray [3,3] (minimum value is 3).
24 * 3 * (3+3) = 3 * 6 = 18.
25 * 
26 * Example 3:
27 * 
28 * Input: nums = [3,1,<u>5,6,4</u>,2]
29 * Output: 60
30 * Explanation: The maximum min-product is achieved with the subarray [5,6,4] (minimum value is 4).
31 * 4 * (5+6+4) = 4 * 15 = 60.
32 * 
33 *  
34 * Constraints:
35 * 
36 * 	1 <= nums.length <= 10^5
37 * 	1 <= nums[i] <= 10^7
38 * 
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/maximum-subarray-min-product/
43// discuss: https://leetcode.com/problems/maximum-subarray-min-product/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48    pub fn max_sum_min_product(nums: Vec<i32>) -> i32 {
49        0
50    }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57    use super::*;
58
59    #[test]
60    fn test_1856() {
61    }
62}
63


Back
© 2025 bowen.ge All Rights Reserved.