#C12876. Palindrome Formation with Limited Removal
Palindrome Formation with Limited Removal
Palindrome Formation with Limited Removal
You are given a string s
. Your task is to determine:
- Whether
s
can be rearranged to form a palindrome. - Whether it is possible to remove at most one character from
s
such that the remaining characters can be rearranged to form a palindrome.
A string is said to be able to form a palindrome if at most one character occurs an odd number of times. For the second part, if the string already meets the criteria, no removal is needed.
The input will consist of multiple test cases. For each test case, output two results separated by a space. The first result is "YES" if the string can be rearranged into a palindrome, otherwise "NO". The second result is "YES" if after removing at most one character the string can be rearranged into a palindrome, otherwise "NO".
inputFormat
The first line of input contains an integer T
which represents the number of test cases. Each of the following T
lines contains a non-empty string s
.
Example:
5 civic ivicc hello a abca
outputFormat
For each test case, output a single line with two tokens separated by a space. The first token should be "YES" if the string can be rearranged to form a palindrome, otherwise "NO". The second token should be "YES" if it is possible (by removing at most one character) to rearrange the string into a palindrome, otherwise "NO".
Example Output:
YES YES YES YES NO NO YES YES NO YES## sample
5
civic
ivicc
hello
a
abca
YES YES
YES YES
NO NO
YES YES
NO YES
</p>