Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Sum of Subarray Ranges
Bookmark
Brute Force
Monotonic Stack
Input
Input 1
Input 2
Input 3
Custom
nums
=
[1, 2, 3]
total =
0
1
0
2
1
3
2
total =
0
1
0
2
1
3
2
total =
0
1
0
2
1
3
2
total =
0
1
0
2
1
3
2
i
subarrays starting at
i = 0
total =
1
1
0
2
1
3
2
j
i
[0..1]
2
-
1
=
1
→ total += 1
total =
3
1
0
2
1
3
2
j
i
[0..2]
3
-
1
=
2
→ total += 2
total =
3
1
0
2
1
3
2
i
subarrays starting at
i = 1
total =
3
1
0
2
1
3
2
j
i
[1..1]
2
-
2
=
0
→ total += 0
total =
4
1
0
2
1
3
2
i
subarrays starting at
i = 2
total =
4
1
0
2
1
3
2
j
i
[2..2]
3
-
3
=
0
→ total += 0
total =
4
1
0
2
1
3
2
sum of ranges =
4
algo
master
.
io
Step:
Brute force: add (max - min) of every subarray to a running total.
0 / 11
Input
Input 1
Input 2
Input 3
Custom
nums
=
[1, 2, 3]
0 / 11
algo
master
.
io
Step:
Brute force: add (max - min) of every subarray to a running total.