CitadelOA #4
Count Distinct Palindromic Substrings
Estimated MediumJudge-ready
Topics (AI-labelled)PalindromesStrings
Count the palindromic substrings with distinct text; multiple occurrences count only once. The correct answer for the long original OCR example abcddcbabcdcdaadcdcbabcddcb is 26, not 27; the original enumeration contains duplicates and substrings that do not exist.
Input
One line containing a lowercase string; complete OCR range 1≤length≤5000.
Output
Output a single integer, the answer.
Example 1
Input:
mokkori
Output:
7
Example 2
Input:
aabaa
Output:
5
Example 3
Input:
abcddcbabcdcdaadcdcbabcddcb
Output:
26
Example notes
The outputs of the three public examples are, in order: 7; 5; 26. These answers were verified by independent enumeration or direct simulation.
Editorial
Loading solution…