#K726. Taco Palindrome Rearrangement
Taco Palindrome Rearrangement
Taco Palindrome Rearrangement
Given a string s
, determine whether it is possible to rearrange its characters to form a palindrome.
A string is a palindrome if it reads the same forwards and backwards. It can be shown that a string can be rearranged into a palindrome if and only if at most one character has an odd frequency. In mathematical notation, if freq(c) denotes the frequency of character c in the string, then the string can be rearranged into a palindrome if and only if
$$ \sum_{c \in \Sigma} \big[\text{freq}(c) \bmod 2\big] \le 1 $$
Your task is to implement a solution that, given multiple strings, outputs "POSSIBLE" if a palindrome permutation is possible for the given string, or "IMPOSSIBLE" otherwise.
Input and output will be provided via standard input and standard output respectively.
inputFormat
The first line contains an integer T
representing the number of test cases. Each of the following T
lines contains a single string s
.
Example:
3 civic ivicc google
outputFormat
For each test case, output on a new line "POSSIBLE" if the input string can be rearranged to form a palindrome, otherwise output "IMPOSSIBLE".
Example:
POSSIBLE POSSIBLE IMPOSSIBLE## sample
3
civic
ivicc
google
POSSIBLE
POSSIBLE
IMPOSSIBLE
</p>