You are given a string s of lowercase letters. Count the number of ways to partition s into one or more contiguous, non-overlapping pieces (covering the whole string, in order) such that every piece is itself a palindrome.
Line 1: the string s.
A single integer: the number of all-palindrome partitions of s.
Example 1
Input
aa
Expected
2
Explanation
The string "aa" can be split as "a"+"a" or kept whole as "aa" — both are valid all-palindrome partitions, giving a count of 2.
Example 2
Input
aba
Expected
2
Explanation
"aba" can be kept whole (itself a palindrome) or split into three single letters "a"+"b"+"a"; every other split contains a non-palindromic piece, so the count is 2.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →