Problem Brief
Palindrome Counter
INTERNFULLTIMEOA
A palindrome is a string that reads the same from the left and from the right. For example, mom and
tacocat are palindromes, as are any single-character strings. Given a string, determine the number
of its substrings that are palindromes.
Function Description
Complete the function countPalindromes in the editor.
countPalindromes has the following parameter:
string s: the string to analyze
Returns
int: an integer that represents the number of palindromic substrings in the given string
1Example 1
Input
s = "tacocat"
Output
10
Explanation
Palindromic substrings are ['t', 'a', 'c', 'o', 'c', 'a', 't', 'coc', 'acoca', 'tacocat']. There are 10 palindromic substrings.
2Example 2
Input
s = "aaa"
Output
6
Explanation
There are 6 possible substrings of s: {'a', 'a', 'a', 'aa', 'aa', 'aaa'}. All of them are palindromes, so return 6.
3Example 3
Input
s = "abccba"
Output
9
Explanation
There are 21 possible substrings of s, the following 9 of which are palindromes: {'a', 'a', 'b', 'b', 'c', 'c', 'cc', 'bccb', 'abccba'}.
4Example 4
Input
s = "daata"
Output
7
Explanation
There are 15 possible substrings of s, the following 7 of which are palindromes: {'a', 'a', 'a', 'aa', 'ata', 'd', 't'}.
Constraints
Limits and guarantees your solution can rely on.
1 ≤ |s| ≤ 5 x 103
each character of s, s[i] ∈ ['a'-'z'].