A palindrome is a word that is the same backwards as it is forwards (e.g. tattarrattat
). Even though most words aren't palindromes, you can always remove or change letters from the word to make it a palindrome (remember that all words of length or are palindromes). For example, larry
is not a palindrome, but removing/changing a few letters yields arra
, which is a palindrome.
Your task is to determine the minimum number of characters you need to remove or change to make a word a palindrome.
Input Specification
The first line will a string , the word you must turn into a palindrome. will contain lowercase alphanumeric characters.
Output Specification
Output the minimum number of characters needed to make a word a palindrome.
Sample Input 1
tattarrattat
Sample Output 1
0
Sample Input 2
larry
Sample Output 2
2
Sample Input 3
11abcdcbaa00
Sample Output 3
3
Explanation for Sample 3
One solution would be to turn the 1
s into 0
s, and remove the last a
, yielding 00abcdcba00
.
Comments