#C2213. Consistent Palindrome Transformation
Consistent Palindrome Transformation
Consistent Palindrome Transformation
Given a string s
, determine if it is possible to transform the string into a palindrome by replacing its characters in a consistent manner. A palindrome is a string that reads the same forwards and backwards. For a string to be rearranged (or consistently replaced) into a palindrome, at most one character may appear an odd number of times. In other words, if more than one character has an odd frequency, it is impossible to form a palindrome.
Your task is to process multiple test cases and, for each, output YES
if the string can be transformed into a palindrome and NO
otherwise.
The frequency criteria can be summarized by the formula in LaTeX:
$$\text{allowed odd characters} \leq 1$$
inputFormat
The input is read from stdin and is structured as follows:
- The first line contains an integer T representing 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 to stdout containing YES
if the string can be transformed into a palindrome, and NO
otherwise.
3
abba
abcba
abcd
YES
YES
NO
</p>