Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Palindrome Partitioning II
Bookmark
Recursion
Palindrome Table
Expand Around Center
Input
Simple
Palindrome heavy
Full palindrome
Mixed
Custom
s
=
aab
s =
"aab"
n =
3
s
a
0
a
1
b
2
cuts
0
0
1
1
2
2
fewest cuts so every piece of "aab" is a palindrome?
s =
"aab"
n =
3
s
a
0
a
1
b
2
cuts
0
0
1
1
2
2
fewest cuts so every piece of "aab" is a palindrome?
s =
"aab"
n =
3
s
a
0
a
1
b
2
center 0
cuts
0
0
1
1
2
2
center = 0
grow odd and even palindromes around 'a'
s =
"aab"
n =
3
s
a
0
a
1
b
2
center 0
cuts
0
0
1
1
2
2
the whole prefix is a palindrome:
cuts[0]
=
0
s =
"aab"
n =
3
s
a
0
a
1
b
2
center 0
cuts
0
0
1
1
2
2
"aa"
is a palindrome (s[0..1], even)
s =
"aab"
n =
3
s
a
0
a
1
b
2
center 0
cuts
0
0
0
1
2
2
s =
"aab"
n =
3
s
a
0
a
1
b
2
center 1
+1
cuts
0
0
0
1
2
2
cuts[
0
] + 1 =
1
is not better, keep
cuts[1] = 0
s =
"aab"
n =
3
s
a
0
a
1
b
2
center 1
cuts
0
0
0
1
2
2
s =
"aab"
n =
3
s
a
0
a
1
b
2
center 2
cuts
0
0
0
1
2
2
"b"
is a palindrome (s[2..2])
s =
"aab"
n =
3
s
a
0
a
1
b
2
center 2
cuts
0
0
0
1
1
2
s =
"aab"
n =
3
cut
s
a
0
a
1
b
2
cuts
0
0
0
1
1
2
aa
|
b
, 1 cut
algo
master
.
io
Step:
Fewest cuts so every piece of "aab" is a palindrome?
0 / 19
Input
Simple
Palindrome heavy
Full palindrome
Mixed
Custom
s
=
aab
0 / 19
algo
master
.
io
Step:
Fewest cuts so every piece of "aab" is a palindrome?