Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Minimum Deletions to Make String Balanced
Bookmark
Brute Force
Prefix + Suffix
Single Pass DP
Input
Standard
All b's first
Mixed
Alternating
Custom
s
=
aababbab
s
a
0
a
1
b
2
a
3
b
4
b
5
a
6
b
7
bLeft = -
aRight = -
minDel = 8
s
a
0
a
1
b
2
a
3
b
4
b
5
a
6
b
7
bLeft = -
aRight = -
minDel = 8
s
a
0
a
1
b
2
a
3
b
4
b
5
a
6
b
7
k = 0
bLeft = 0
aRight = 4
minDel = 8
4 'a'(s) right of the split
s
a
0
a
1
b
2
a
3
b
4
b
5
a
6
b
7
k = 1
bLeft = 0
aRight = 3
minDel = 4
3 'a'(s) right of the split
s
a
0
a
1
b
2
a
3
b
4
b
5
a
6
b
7
k = 2
bLeft = 0
aRight = 2
minDel = 2
new best: 2
s
a
0
a
1
b
2
a
3
b
4
b
5
a
6
b
7
k = 3
bLeft = 1
aRight = 2
minDel = 2
best stays 2
s
a
0
a
1
b
2
a
3
b
4
b
5
a
6
b
7
k = 4
bLeft = 1
aRight = 1
minDel = 2
best stays 2
s
a
0
a
1
b
2
a
3
b
4
b
5
a
6
b
7
k = 5
bLeft = 2
aRight = 1
minDel = 2
best stays 2
s
a
0
a
1
b
2
a
3
b
4
b
5
a
6
b
7
k = 7
bLeft = -
aRight = -
minDel = 2
k = 7: a's on the left, b's on the right
s
a
0
a
1
b
2
a
3
b
4
b
5
a
6
b
7
k = 8
bLeft = -
aRight = -
minDel = 2
k = 8: a's on the left, b's on the right
s
a
0
a
1
b
2
a
3
b
4
b
5
a
6
b
7
bLeft = -
aRight = -
minDel = 2
minimum deletions = 2
algo
master
.
io
Step:
A balanced string is every 'a' before every 'b'. How few deletions fix "aababbab"?
0 / 38
Input
Standard
All b's first
Mixed
Alternating
Custom
s
=
aababbab
0 / 38
algo
master
.
io
Step:
A balanced string is every 'a' before every 'b'. How few deletions fix "aababbab"?