#K63332. Can Form Palindrome
Can Form Palindrome
Can Form Palindrome
Given a string s, determine if its characters can be rearranged to form a palindrome. A string is a palindrome if it reads the same forward and backward. The necessary and sufficient condition for a string to be rearranged into a palindrome is that at most one character appears an odd number of times. Formally, let \(f(c)\) denote the frequency count of a character \(c\) in string \(s\). The string can be rearranged into a palindrome if and only if:
\[ \sum_{c \in \Sigma} [f(c) \mod 2 \neq 0] \leq 1 \]
Your task is to implement a program that reads multiple test cases from standard input and, for each test case, outputs "YES" if the given string can be rearranged into a palindrome and "NO" otherwise.
inputFormat
The first line of input contains an integer \(T\) (\(1 \leq T \leq 10^5\)) denoting the number of test cases. Each of the following \(T\) lines contains a non-empty string \(s\) consisting of lowercase English letters.
Example:
3 aabb abc racecar
outputFormat
For each test case, output a single line containing "YES" if the string can be rearranged to form a palindrome, or "NO" otherwise.
Example:
YES NO YES## sample
3
aabb
abc
racecar
YES
NO
YES
</p>