#C2707. One Replacement Palindrome
One Replacement Palindrome
One Replacement Palindrome
You are given a string s
. Your task is to determine whether it is possible to transform s
into a palindrome by replacing at most one character. A string is a palindrome if it reads the same forwards and backwards, i.e., it satisfies the condition $$s[i] = s[n-1-i]$$ for all valid indices i
, where n
is the length of the string.
If the string is already a palindrome or can become one by altering at most one character, output Yes
; otherwise, output No
.
Note: The replacement operation can be applied to only one character at most.
inputFormat
The first line contains a single integer T
(1 ≤ T ≤ 105), the number of test cases. Each of the next T
lines contains a non-empty string s
consisting of lowercase English letters. The length of s
will be at most 105.
outputFormat
For each test case, output a single line containing either Yes
if the string can be transformed into a palindrome with at most one replacement, or No
otherwise.
4
abca
racecar
abc
a
Yes
Yes
No
Yes
</p>