A palindrome is a word which is spelled the same backwards and forwards. For example, "racecar" is a palindrome as is "redder". A double palindrome is a palindrome whose halves are also palindromes. For example, "abbabba" is a double palindrome, as the half "abba" is also a palindrome. Similarily, "abaababaaba" is a triple palindrome and so on. Your task is to take a string and return the degree of palindromess. If the string is not a palindrome, return 0.
In order to avoid ambiguity in some edge-cases, the first two letters are guranteed to be different, and the input has at least three letters.
The input string consists entirely of lowercase letters.
Examples
"notapalindrome" -> 0 "madam" -> 1 "xyxxxyx" -> 1 "racecarracecar" -> 2 "ababababa" -> 3 "abbaabbaabbaabba" -> 3
xyxxxyx, It's a palindrome and its halves contain non-trivial palindromes but are not actually palindromes themselves. \$\endgroup\$