Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Online Stock Span
Bookmark
Brute Force
Monotonic Stack
Input
Input 1
Input 2
Input 3
Custom
prices
=
[100, 80, 60, 70, 60, 75, 85]
span =
0
prices
100
0
80
1
60
2
70
3
60
4
75
5
85
6
spans
span =
0
prices
100
0
80
1
60
2
70
3
60
4
75
5
85
6
spans
span =
1
prices
100
0
80
1
60
2
70
3
60
4
75
5
85
6
i
spans
1
spans[0] =
1
span =
1
prices
100
0
80
1
60
2
70
3
60
4
75
5
85
6
j
i
spans
1
1
spans[1] =
1
span =
1
prices
100
0
80
1
60
2
70
3
60
4
75
5
85
6
i
spans
1
1
1
day
70
: count consecutive earlier days that are
≤ it
span =
2
prices
100
0
80
1
60
2
70
3
60
4
75
5
85
6
j
i
spans
1
1
1
2
spans[3] =
2
span =
1
prices
100
0
80
1
60
2
70
3
60
4
75
5
85
6
i
spans
1
1
1
2
1
day
75
: count consecutive earlier days that are
≤ it
span =
4
prices
100
0
80
1
60
2
70
3
60
4
75
5
85
6
j
i
spans
1
1
1
2
1
60
<= 75 → span =
4
span =
2
prices
100
0
80
1
60
2
70
3
60
4
75
5
85
6
j
i
spans
1
1
1
2
1
4
75
<= 85 → span =
2
span =
5
prices
100
0
80
1
60
2
70
3
60
4
75
5
85
6
j
i
spans
1
1
1
2
1
4
60
<= 85 → span =
5
prices
100
0
80
1
60
2
70
3
60
4
75
5
85
6
spans
1
1
1
2
1
4
6
spans =
[1, 1, 1, 2, 1, 4, 6]
algo
master
.
io
Step:
Brute force: for each day, count consecutive earlier days <= its price.
0 / 32
Input
Input 1
Input 2
Input 3
Custom
prices
=
[100, 80, 60, 70, 60, 75, 85]
0 / 32
algo
master
.
io
Step:
Brute force: for each day, count consecutive earlier days <= its price.