#K53332. Palindrome Permutation Checker
Palindrome Permutation Checker
Palindrome Permutation Checker
Given a string s, determine if any permutation of the string can be rearranged to form a palindrome. A string can form a palindrome if and only if the number of characters with an odd frequency is at most one. In mathematical terms, if we denote by \(f(c)\) the frequency of character \(c\) in s, then s can be rearranged into a palindrome if and only if
[ \sum_{c} [f(c) \bmod 2 \neq 0] \leq 1 ]
For example, the string "civic" is already a palindrome, and "ivicc" can be rearranged into "civic", hence both are valid. On the other hand, "hello" cannot be rearranged to form a palindrome.
inputFormat
The input is taken from standard input (stdin) and consists of multiple test cases. The first line contains an integer T
representing the number of test cases. Each of the following T
lines contains a non-empty string s
consisting of lowercase letters.
outputFormat
For each test case, print a single line to standard output (stdout) containing YES
if the string can be rearranged to form a palindrome, or NO
otherwise.
6
civic
ivicc
hello
aabb
abc
a
YES
YES
NO
YES
NO
YES
</p>