Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Maximum Width Ramp
Bookmark
Brute Force
Sort + Index
Monotonic Stack
Input
Input 1
Input 2
Input 3
Custom
nums
=
[6, 0, 8, 2, 1, 5]
maxWidth =
0
6
0
0
1
8
2
2
3
1
4
5
5
maxWidth =
0
6
0
0
1
8
2
2
3
1
4
5
5
maxWidth =
0
6
0
0
1
8
2
2
3
1
4
5
5
i
left endpoint
6
: scan from the right for the farthest j that is
≥ it
maxWidth =
0
6
0
0
1
8
2
2
3
1
4
5
5
j
i
1
< 6 → move left
maxWidth =
2
6
0
0
1
8
2
2
3
1
4
5
5
i
left endpoint
0
: scan from the right for the farthest j that is
≥ it
maxWidth =
4
6
0
0
1
8
2
2
3
1
4
5
5
i
left endpoint
8
: scan from the right for the farthest j that is
≥ it
maxWidth =
4
6
0
0
1
8
2
2
3
1
4
5
5
j
i
1
< 8 → move left
maxWidth =
4
6
0
0
1
8
2
2
3
1
4
5
5
j
i
nothing to the right is >= it → no ramp starts here
maxWidth =
4
6
0
0
1
8
2
2
3
1
4
5
5
i
left endpoint
1
: scan from the right for the farthest j that is
≥ it
maxWidth =
4
6
0
0
1
8
2
2
3
1
4
5
5
i
left endpoint
5
: scan from the right for the farthest j that is
≥ it
maxWidth =
4
6
0
0
1
8
2
2
3
1
4
5
5
width 4
max width ramp =
4
algo
master
.
io
Step:
Brute force: for each i, scan j from the right for the widest valid ramp.
0 / 20
Input
Input 1
Input 2
Input 3
Custom
nums
=
[6, 0, 8, 2, 1, 5]
0 / 20
algo
master
.
io
Step:
Brute force: for each i, scan j from the right for the widest valid ramp.