#C10854. Can Form Palindrome
Can Form Palindrome
Can Form Palindrome
Given a string s
consisting of lowercase letters, determine whether it is possible to rearrange the characters of s
to form a palindrome. A palindrome is a string that reads the same backwards as forwards. Mathematically, a string can be rearranged into a palindrome if and only if the number of characters with an odd frequency is at most one, i.e., $$ \#\{c : freq(c) \text{ is odd}\} \le 1.$$
If a palindromic arrangement exists, output one possible arrangement; otherwise, output an empty string.
inputFormat
The input consists of a single line containing the string s
(possibly empty) made up of lowercase English letters.
outputFormat
Output a single line containing one possible palindromic arrangement of s
if one exists. If it is impossible to form any palindrome, output an empty string.
code