Problem
Let's say that a word is almost a palindrome if it is possible to remove one of its letters so that the word becomes a palindrome. Your task is to write a program that for a given word determines which letter to remove to get a palindrome.
The shortest code to do this in any programming language wins.
Input
Input consists of a word of lowercase letters from 2 to 1000 characters long.
Output
Output the 1-indexed position (leftmost letter has position 1, the next one has position 2 and so on) of the letter which should be removed. If there are possible choices that lead to the palindrome, output any of those positions. Note that you are required to remove a letter even if the given word is already a palindrome. If the given word is not almost a palindrome, output -1.
Examples
The input:
racercar
might produce either of these outputs:
4
5
because removing the 4
th letter produces racrcar
and removing the 5
th letter produces racecar
, which are both palindromes.
Also, the input
racecar
can still produce the output
4
because removing the 4
th letter to produce raccar
is still a palindrome.
The input
golf
should produce the output
-1
because there is no way to remove a single letter to make it a palindrome.