Odd Palindrome
Jump to navigation
Jump to search
This problem asks us to find the lengths of palindromic substrings within a string, and return whether they are all odd.
Given a max size of 100, it suffices to iterate over all substrings and check whether they are palindromes. This is 100^3, which is fast enough. We could do better if we really wanted. Any even palindrome has a pair of letters at the middle, and any paired letters forms a palindrome. We can simply walk the string and check for a pair of letters, if none exist, the word is odd. This can be done with regex.