Dashboard
LC #907
Sum of Subarray Minimums
Pattern · ?AmazonGoogleBloomberg
Problem
Find the sum of the minimum element of every subarray of a given array.
Constraints
- 1 ≤ arr.length ≤ 3×10⁴
- 1 ≤ arr[i] ≤ 3×10⁴
- Answer mod 10⁹+7
Example
- Input
- arr = [3, 1, 2, 4]
- Output
- 17
- Why
- Subarrays: [3]=3,[1]=1,[2]=2,[4]=4,[3,1]=1,[1,2]=1,[2,4]=2,[3,1,2]=1,[1,2,4]=1,[3,1,2,4]=1 → sum=17
Spot the pattern
Which pattern cracks it?
Hints
One at a time