#C14252. Rearrange to Palindrome
Rearrange to Palindrome
Rearrange to Palindrome
Given a string s
consisting of lowercase alphabetical characters, determine if the characters of s
can be rearranged to form a palindrome.
A string can be rearranged into a palindrome if at most one character has an odd frequency. In mathematical terms, let \( f(c) \) be the frequency of character \( c \) in the string. Then the string can form a palindrome if and only if
$$\sum_{c\in\text{alphabet}} \mathbb{1}_{\{f(c)\;\%\;2\neq 0\}} \leq 1$$
For example, the string "racecar" can be rearranged to form a palindrome, while "hello" cannot.
inputFormat
The input consists of a single line containing a string s
of lowercase alphabetical characters. The string may be empty.
outputFormat
Output a single line: True
if the string can be rearranged to form a palindrome, and False
otherwise.## sample
racecar
True