Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Count Binary Substrings
Bookmark
Brute Force
Group Counting
Two Counters
Input
00110011
10101
00110
Custom
s
=
00110011
count =
0
0
1
2
3
4
5
6
7
0
0
1
1
0
0
1
1
count =
0
0
1
2
3
4
5
6
7
0
0
1
1
0
0
1
1
window =
[0, 3]
count =
0
0
1
2
3
4
5
6
7
0
0
1
1
0
0
1
1
i
s[1] = '0'
==
'0'
first half still one run
window =
[0, 7]
count =
1
0
1
2
3
4
5
6
7
0
0
1
1
0
0
1
1
i
found
0011
window [0, 7] = "00110011"
first half must be all '0'
window =
[1, 2]
count =
2
0
1
2
3
4
5
6
7
0
0
1
1
0
0
1
1
i
found
0011
01
"01"
→ equal runs, count =
2
window =
[1, 6]
count =
2
0
1
2
3
4
5
6
7
0
0
1
1
0
0
1
1
i
found
0011
01
"011001"
→ not equal runs, skip
window =
[2, 5]
count =
2
0
1
2
3
4
5
6
7
0
0
1
1
0
0
1
1
i
found
0011
01
s[5] = '0'
==
'0'
second half still one run
window =
[3, 4]
count =
3
0
1
2
3
4
5
6
7
0
0
1
1
0
0
1
1
i
found
0011
01
1100
s[3] = '1'
==
'1'
first half still one run
window =
[4, 5]
count =
4
0
1
2
3
4
5
6
7
0
0
1
1
0
0
1
1
i
found
0011
01
1100
10
s[4] = '0'
==
'0'
first half still one run
window =
[5, 6]
count =
5
0
1
2
3
4
5
6
7
0
0
1
1
0
0
1
1
i
found
0011
01
1100
10
0011
window [5, 6] = "01"
first half must be all '0'
count =
6
0
1
2
3
4
5
6
7
0
0
1
1
0
0
1
1
i
found
0011
01
1100
10
0011
01
count =
6
equal-run substrings
algo
master
.
io
Step:
Count substrings of "00110011" with equal runs of 0s and 1s
0 / 75
Input
00110011
10101
00110
Custom
s
=
00110011
0 / 75
algo
master
.
io
Step:
Count substrings of "00110011" with equal runs of 0s and 1s