#C9161. Transformable Palindrome

    ID: 53224 Type: Default 1000ms 256MiB

Transformable Palindrome

Transformable Palindrome

Given a string (s) consisting of lowercase English letters, determine whether it is possible to transform (s) into a palindrome by changing at most one character. The allowed transformation is to replace a character with its lexicographically adjacent character (i.e. either the previous or the next character in the alphabet). Formally, for any mismatch at indices (i) and (n-1-i) (where (n) is the length of (s)), the absolute difference (|s[i]-s[n-1-i]|) must be exactly 1 if a mismatch is to be corrected. If more than one mismatch occurs that does not meet this condition, the transformation is impossible.

For example, consider the string "abca":

  • Comparing the second and third characters, (b) and (c), they differ by exactly 1 so the string can be transformed into a palindrome. Thus, the answer is YES.

Your task is to read multiple test cases from standard input and, for each, output YES if the string (s) can be transformed into a palindrome according to the above rules, otherwise output NO.

inputFormat

The first line of input contains an integer (T) denoting the number of test cases. Each of the following (T) lines contains a non-empty string (s) consisting of lowercase English letters.

outputFormat

For each test case, output a single line containing either (YES) if it is possible to transform the string into a palindrome by changing at most one character to its adjacent character, or (NO) otherwise.## sample

5
abcd
racecar
abba
abca
redivider
NO

YES YES YES YES

</p>