Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Sum of Subarray Minimums
Bookmark
Brute Force
Contribution
Stack + DP
Input
Input 1
Input 2
Input 3
Custom
arr
=
[3, 1, 2, 4]
total =
0
3
0
1
1
2
2
4
3
total =
0
3
0
1
1
2
2
4
3
total =
0
3
0
1
1
2
2
4
3
i
subarrays starting at
i = 0
total =
4
3
0
1
1
2
2
4
3
j
i
[0..1] min =
1
→ total += 1
total =
5
3
0
1
1
2
2
4
3
j
i
[0..2] min =
1
→ total += 1
total =
6
3
0
1
1
2
2
4
3
i
subarrays starting at
i = 1
total =
8
3
0
1
1
2
2
4
3
j
i
[1..2] min =
1
→ total += 1
total =
9
3
0
1
1
2
2
4
3
i
subarrays starting at
i = 2
total =
11
3
0
1
1
2
2
4
3
j
i
[2..2] min =
2
→ total += 2
total =
13
3
0
1
1
2
2
4
3
i
subarrays starting at
i = 3
total =
17
3
0
1
1
2
2
4
3
sum of minimums =
17
algo
master
.
io
Step:
Brute force: add the minimum of every subarray to a running total.
0 / 16
Input
Input 1
Input 2
Input 3
Custom
arr
=
[3, 1, 2, 4]
0 / 16
algo
master
.
io
Step:
Brute force: add the minimum of every subarray to a running total.