Given an integer array arr, return the sum of the minimum value of every subarray. Since the answer can be large, return it modulo 1,000,000,007. Example: Input: arr = [3,1,2,4] Output: 17 Explanation: The minimum of each subarray contributes to the final sum. Pattern focus: Range Contribution using monotonic stacks.
arr = integer array
sum of minimums across all subarrays, modulo 1,000,000,007
Example 1:
Input:
arr = [3,1,2,4]
Output:
17
Explanation:
Count how many subarrays each element becomes the minimum for.
Example 2:
Input:
arr = [11,81,94,43,3]
Output:
444
Explanation:
Contribution counting avoids enumerating all subarrays.