#C8578. Check Palindrome by Removing One Character
Check Palindrome by Removing One Character
Check Palindrome by Removing One Character
Given a non-empty string s
consisting of lowercase English letters, determine whether it is possible to obtain a palindrome by removing exactly one character from s
. A string is considered a palindrome if it reads the same forwards and backwards. Formally, a string s
of length n is a palindrome if it satisfies
$$ s[i] = s[n-i+1] \quad \text{for all } 1 \leq i \leq n $$
If the string is already a palindrome, then the answer should be NO
since removing a character is not allowed to keep the property.
You are required to process multiple test cases.
inputFormat
The first line of the input contains a single integer t
indicating the number of test cases. Each of the following t
lines contains a single string s
.
outputFormat
For each test case, output a single line containing either YES
if it is possible to obtain a palindrome by removing exactly one character, or NO
otherwise.
1
abca
YES
</p>