#K36952. Palindrome Rearrangement
Palindrome Rearrangement
Palindrome Rearrangement
You are given T strings. For each string, determine whether it is possible to rearrange its characters to form a palindrome.
A string can be rearranged into a palindrome if and only if the number of characters with an odd frequency is at most one. Mathematically, if we let \(f(c)\) be the frequency of character \(c\) in the string, then the string can form a palindrome if \[ \sum_{c} [f(c) \mod 2 \neq 0] \le 1 \] where \([P]\) equals 1 if the predicate \(P\) is true, and 0 otherwise.
Example:
- For the string
aabb
: that can form the palindrome "abba" or "baab" hence the answer isYES
. - For
abc
: it cannot form any palindrome so the answer isNO
. - For
civic
: the string is already a palindrome and the answer isYES
.
inputFormat
The first line contains an integer T (the number of test cases). Each of the following T lines contains a non-empty string S.
It is guaranteed that the string consists of lowercase English letters.
outputFormat
For each test case, print a single line containing YES
if it is possible to rearrange the string into a palindrome, otherwise print NO
.
3
aabb
abc
civic
YES
NO
YES
</p>