AmazonOA #127
Palindromic Substrings
Estimated MediumJudge-ready
Topics (AI-labelled)PalindromesStrings
Count all palindromic substrings; substrings with the same characters but different start or end positions are counted separately. The first sentence of the source is truncated; this definition is made clear by the title and by the example in which aaa lists six positional substrings.
Input
One line with a lowercase string of length 1..1000.
Output
Output a single integer answer.
Example 1
Input:
abc
Output:
3
Example 2
Input:
aaa
Output:
6
Example 3
Input:
abba
Output:
6
Example notes
Example 1: three single characters, 3 in total. Example 2: three a, two aa and one aaa, 6 in total. Example 3: four single characters plus bb and abba, 6 in total.
Editorial
Loading solution…