Count Distinct Palindromic Substrings
Problem statement
Count the distinct nonempty palindromic substrings of s. A substring is contiguous, and a palindrome reads the same forward and backward.
For this exercise, assume equal substring text is counted once, even when it occurs at different or overlapping positions. Return the number of different palindromic text values. The empty string contains none and returns 0.
Function
countDistinctPalindromes(s: String) → intExamples
Example 1
s = "ababa"return = 5The distinct values are a, b, aba, bab and ababa.
Example 2
s = "aaaa"return = 4The four distinct values are a, aa, aaa and aaaa, regardless of repeated occurrences.
Example 3
s = ""return = 0The empty substring is not counted.
Constraints
0 <= s.length <= 5000.- Every character is a lowercase English letter.