Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Continuous Subarrays
Bookmark
Brute Force
Sorted Map
Monotonic Deques
Input
Standard
Longer
Tight
Custom
nums
=
[5, 4, 2, 4]
max - min ≤ 2
count
0
5
4
2
4
0
1
2
3
stretch every start until the spread passes 2
max - min ≤ 2
count
0
5
4
2
4
0
1
2
3
stretch every start until the spread passes 2
max 5 - min 5 =
0
count
1
[0..0]
5
4
2
4
0
1
2
3
i
j
[0..0]
is continuous, count =
1
max 5 - min 4 =
1
count
2
[0..1]
5
4
2
4
0
1
2
3
i
j
[0..1]
is continuous, count =
2
max 4 - min 4 =
0
count
2
[1..1]
5
4
2
4
0
1
2
3
i
j
start at i =
1
max 4 - min 4 =
0
count
3
[1..1]
5
4
2
4
0
1
2
3
i
j
[1..1]
is continuous, count =
3
max 4 - min 2 =
2
count
4
[1..3]
5
4
2
4
0
1
2
3
i
j
[1..3] min
2
, max
4
, spread
2
max 2 - min 2 =
0
count
5
[2..2]
5
4
2
4
0
1
2
3
i
j
start at i =
2
max 4 - min 2 =
2
count
6
[2..3]
5
4
2
4
0
1
2
3
i
j
[2..3] min
2
, max
4
, spread
2
max 4 - min 4 =
0
count
7
[3..3]
5
4
2
4
0
1
2
3
i
j
start at i =
3
max - min ≤ 2
count
8
5
4
2
4
0
1
2
3
8
continuous subarrays
algo
master
.
io
Step:
Start: try every start index and stretch it while max - min stays within 2
0 / 23
Input
Standard
Longer
Tight
Custom
nums
=
[5, 4, 2, 4]
0 / 23
algo
master
.
io
Step:
Start: try every start index and stretch it while max - min stays within 2