Subarray Minimums Total
Return the sum of over every contiguous subarray of nums, modulo .
Requirements
- : count how many subarrays each element is the minimum of, using monotonic stacks for its previous-smaller and next-smaller-or-equal positions.
Examples
EXAMPLE WALKTHROUGHclassic
A guided view of the published example, not a trace of your code.
INPUT
[[3,1,2,4]]TASKsubarray_minimums_total()
EXPECTED OUTPUT
17Start with the input values shown in this example.
Example 1 of 3
Input: nums = [3,1,2,4]
Output: 17
Explanation: classic
Input: nums = [11,81,94,43,3]
Output: 444
Explanation: larger
Input: nums = [1]
Output: 1
Explanation: single
Hint 1
If element i is the minimum for L choices of left end and R choices of right end, it contributes nums[i] * L * R.
Hint 2
Use strict on one side and non-strict on the other so equal values are counted once.