You are given an array strength where each element represents the strength of a wizard. For every non-empty subarray, let its power be the minimum strength in the subarray multiplied by the sum of strengths in the subarray. Return the total power of all subarrays modulo 1,000,000,007. Example: Input: strength = [1,3,1,2] Output: 44 Explanation: The total is obtained by summing the power of every subarray. Pattern focus: Range Contribution with monotonic stacks and prefix sums.
strength = array of wizard strengths
total power of all subarrays, modulo 1,000,000,007
Example 1:
Input:
strength = [1,3,1,2]
Output:
44
Explanation:
This is a compact example where multiple subarrays share the same minimum contribution.
Example 2:
Input:
strength = [1,2]
Output:
8
Explanation:
Subarrays [1], [2], and [1,2] contribute 1, 4, and 3 respectively.