Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Count Subarrays With Fixed Bounds
Bookmark
Brute Force
Sliding Window
Input
Input 1
Input 2
Input 3
Custom
nums
=
[1, 3, 5, 2, 7, 5]
,
minK
=
1
,
maxK
=
5
0
1
2
3
4
5
1
3
5
2
7
5
minK =
1
maxK =
5
count =
0
0
1
2
3
4
5
1
3
5
2
7
5
minK =
1
maxK =
5
count =
0
0
1
2
3
4
5
1
3
5
2
7
5
i
j
window min =
1
max =
1
minK =
1
maxK =
5
count =
0
min = 1, max = 1
→ in range but not exactly [
1
,
5
]
0
1
2
3
4
5
1
3
5
2
7
5
i
j
window min =
1
max =
5
minK =
1
maxK =
5
count =
1
[0..3]
: min =
1
, max =
5
0
1
2
3
4
5
1
3
5
2
7
5
i
j
minK =
1
maxK =
5
count =
2
start a new subarray at i = 1
0
1
2
3
4
5
1
3
5
2
7
5
i
j
window min =
2
max =
5
minK =
1
maxK =
5
count =
2
[1..3]
: min =
2
, max =
5
0
1
2
3
4
5
1
3
5
2
7
5
i
j
minK =
1
maxK =
5
count =
2
start a new subarray at i = 2
0
1
2
3
4
5
1
3
5
2
7
5
i
j
window min =
2
max =
7
minK =
1
maxK =
5
count =
2
[2..4]
: min =
2
, max =
7
0
1
2
3
4
5
1
3
5
2
7
5
i
j
window min =
2
max =
2
minK =
1
maxK =
5
count =
2
min = 2, max = 2
→ in range but not exactly [
1
,
5
]
0
1
2
3
4
5
1
3
5
2
7
5
i
j
window min =
7
max =
7
minK =
1
maxK =
5
count =
2
nums[4] = 7
> maxK
→ stop extending
0
1
2
3
4
5
1
3
5
2
7
5
i
j
minK =
1
maxK =
5
count =
2
return 2
fixed-bound subarrays
algo
master
.
io
Step:
Count subarrays whose min is 1 and max is 5
0 / 40
Input
Input 1
Input 2
Input 3
Custom
nums
=
[1, 3, 5, 2, 7, 5]
,
minK
=
1
,
maxK
=
5
0 / 40
algo
master
.
io
Step:
Count subarrays whose min is 1 and max is 5