#K44967. Almost Palindrome Verification
Almost Palindrome Verification
Almost Palindrome Verification
Given a string S, determine if it is an almost palindrome. A string is called an almost palindrome if it can be transformed into a palindrome by changing at most one character. Formally, for a string of length n, there exists at most one index i (with 0 ≤ i < n) such that if you change the character at position i, the resulting string is a palindrome.
Note: A palindrome is a string that reads the same backward as forward. In terms of formula, a string S is a palindrome if:
\(S[i] = S[n-i-1]\) for all \(0 \leq i < n\)
Your task is to check multiple test cases and determine for each whether the string is an almost palindrome.
inputFormat
The first line of input contains an integer T
(1 ≤ T ≤ 105), the number of test cases. Each of the following T
lines contains a single string S
(consisting of lowercase English letters).
Input is provided via standard input (stdin).
outputFormat
For each test case, output a single line containing YES
if the input string is an almost palindrome, or NO
otherwise. The output should be printed to standard output (stdout).
3
abca
racecar
abcdef
YES
YES
NO
</p>