907. Sum of Subarray Minimums Medium
1/**
2 * [907] Sum of Subarray Minimums
3 *
4 * Given an array of integers arr, find the sum of min(b), where b ranges over every (contiguous) subarray of arr. Since the answer may be large, return the answer modulo 10^9 + 7.
5 *
6 * Example 1:
7 *
8 * Input: arr = [3,1,2,4]
9 * Output: 17
10 * Explanation:
11 * Subarrays are [3], [1], [2], [4], [3,1], [1,2], [2,4], [3,1,2], [1,2,4], [3,1,2,4].
12 * Minimums are 3, 1, 2, 4, 1, 1, 2, 1, 1, 1.
13 * Sum is 17.
14 *
15 * Example 2:
16 *
17 * Input: arr = [11,81,94,43,3]
18 * Output: 444
19 *
20 *
21 * Constraints:
22 *
23 * 1 <= arr.length <= 3 * 10^4
24 * 1 <= arr[i] <= 3 * 10^4
25 *
26 */
27pub struct Solution {}
28
29// problem: https://leetcode.com/problems/sum-of-subarray-minimums/
30// discuss: https://leetcode.com/problems/sum-of-subarray-minimums/discuss/?currentPage=1&orderBy=most_votes&query=
31
32// submission codes start here
33
34impl Solution {
35 pub fn sum_subarray_mins(arr: Vec<i32>) -> i32 {
36 0
37 }
38}
39
40// submission codes end
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45
46 #[test]
47 fn test_907() {
48 }
49}
50
Back
© 2025 bowen.ge All Rights Reserved.