AmazonOA #115
Compute Encoded Product Name
Estimated EasyJudge-ready
The input is guaranteed to be a lowercase palindrome. Rearrange all of its characters and output the lexicographically smallest string that is still a palindrome; leaving the original string unchanged is allowed.
Input
One line with a palindrome of length 1..100000, containing only lowercase letters.
Output
Output the lexicographically smallest palindrome.
Example 1
Input:
babab
Output:
abbba
Example 2
Input:
cabbac
Output:
abccba
Example 3
Input:
z
Output:
z
Example notes
Example 1: a appears twice and b three times, so the left half is ab, the center is b and the right half is ba; output abbba. Example 2: the left half is abc, which mirrors to abccba. Example 3: a single z stays unchanged.
Editorial
Loading solution…