Facebook Pixel

Sum of Subarray Minimums

Given an array of integers arr, find the sum of min(b), where b ranges over every (contiguous) subarray of arr.

Input & Output
Input
weights — an array of integers
Output
the sum of subarray minimums
Example
Input
weights = [1, 3, 2]
Output
10
Explanation
SubarrayMin Weight
1 ,3, 21
1, 3, 23
1, 3, 22
1, 3, 21
1, 3, 22
1, 3, 21

The sum of subarray minimums is 1+3+2+1+2+1=10.

Try it yourself

Invest in Yourself
Your new job is waiting. 83% of people that complete the program get a job offer. Unlock unlimited access to all content and features.
Go Pro