Sum of Subarray Minimums⚓︎
Description⚓︎
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.
Example 1:
- Input:
arr = [3,1,2,4] - Output:
17 - Explanation:
Example 2:
- Input:
arr = [11,81,94,43,3] - Output:
444
Constraints:
1 <= arr.length <= 3 * 10^41 <= arr[i] <= 3 * 10^4
Solution⚓︎
- Time complexity: \(O(n)\);
- Space complexity: \(O(n)\).