Count the palindromes inside a string
Given a string s, return how many of its substrings are palindromes: they read the same left to right and right to left. A substring is a contiguous, non-empty piece of s. Pieces at different positions count separately even when their text is equal, and a single character is a palindrome by itself.
Every character matters, spaces included, and uppercase and lowercase letters are different. s has 0 to 1,000 characters. Aim for O(n²) time.
Examples
count_palindromes("abc")→3count_palindromes("aaa")→6count_palindromes("noon")→6