Loading...
Loading...
Loading...
A word is given. A palindromic substring reads the same forwards and backwards. Count every substring that is a palindrome. Substrings at different positions count separately, even if they look the same.
Example 1
Input
aaa
Output
6
a, a, a, aa, aa, aaa.
Example 2
Input
abc
Output
3
Try the problem first. Open one hint at a time.
Every palindrome grows from a centre: one letter or a pair of letters.
From each centre, move outwards while both ends match and count every step.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor