#K12106. Remove One Character to Form Palindrome
Remove One Character to Form Palindrome
Remove One Character to Form Palindrome
Given a string \(s\), determine if it is possible to remove exactly one character from \(s\) such that the resulting string is a palindrome. A string is a palindrome if it reads the same forward and backward, i.e. \(s = s^R\). Note that if the string is already a palindrome, then the answer should be False
because no removal is needed.
For example, for the string "abca", by removing the character at index 1 ('b') or index 2 ('c'), the resulting string "aca" or "aba" (respectively) becomes a palindrome, so the answer is True
. However, for the string "abc", no single removal can produce a palindrome, so the answer is False
.
inputFormat
The first line of input contains an integer \(T\) indicating the number of test cases. Each of the following \(T\) lines contains a non-empty string \(s\) consisting of lowercase letters.
Example:
9 abca abc a aa ab racecar aac caa abcdef
outputFormat
For each test case, output True
if it is possible to remove exactly one character from the given string to make it a palindrome; otherwise, output False
. Each answer should be printed on a new line.
Example:
True False False False True False True True False## sample
9
abca
abc
a
aa
ab
racecar
aac
caa
abcdef
True
False
False
False
True
False
True
True
False
</p>