Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Maximum Score From Removing Substrings
Bookmark
Brute Force
Stack
Counting
Input
Example 1
Example 2
Small ab
Small ba
Custom
s
=
cdbcbbaaabab
,
x
=
4
,
y
=
5
0
1
2
3
4
5
6
7
8
9
10
11
c
d
b
c
b
b
a
a
a
b
a
b
0
1
2
3
4
5
6
7
8
9
10
11
c
d
b
c
b
b
a
a
a
b
a
b
score =
0
held:
b
×0
a
×0
ba
+5
ab
+4
0
1
2
3
4
5
6
7
8
9
10
11
c
d
b
c
b
b
a
a
a
b
a
b
score =
5
held:
b
×0
a
×0
ba
+5
ab
+4
0
1
2
3
4
5
6
7
8
9
10
11
c
d
b
c
b
b
a
a
a
b
a
b
score =
5
held:
b
×0
a
×0
ba
+5
ab
+4
0
1
2
3
4
5
6
7
8
9
10
11
c
d
b
c
b
b
a
a
a
b
a
b
score =
10
held:
b
×0
a
×0
ba
+5
ab
+4
0
1
2
3
4
5
6
7
8
9
10
11
c
d
b
c
b
b
a
a
a
b
a
b
score =
15
held:
b
×0
a
×0
ba
+5
ab
+4
0
1
2
3
4
5
6
7
8
9
10
11
c
d
b
c
b
b
a
a
a
b
a
b
score =
15
held:
b
×0
a
×0
ba
+5
ab
+4
0
1
2
3
4
5
6
7
8
9
10
11
c
d
b
c
b
b
a
a
a
b
a
b
score =
15
held:
b
×0
a
×0
ba
+5
ab
+4
0
1
2
3
4
5
6
7
8
9
10
11
c
d
b
c
b
b
a
a
a
b
a
b
score =
19
held:
b
×0
a
×0
ba
+5
ab
+4
0
1
2
3
4
5
6
7
8
9
10
11
c
d
b
c
b
b
a
a
a
b
a
b
score =
19
held:
b
×0
a
×0
ba
+5
ab
+4
0
1
2
3
4
5
6
7
8
9
10
11
c
d
b
c
b
b
a
a
a
b
a
b
Maximum score =
19
algo
master
.
io
Step:
Start: repeatedly scan for "ab" (+4) and "ba" (+5) until neither is left.
0 / 16
Input
Example 1
Example 2
Small ab
Small ba
Custom
s
=
cdbcbbaaabab
,
x
=
4
,
y
=
5
0 / 16
algo
master
.
io
Step:
Start: repeatedly scan for "ab" (+4) and "ba" (+5) until neither is left.