Rearrange the characters of a string to form the lexicographically smallest palindrome, if possible.
Smallest Palindromic Rearrangement I
gfgGiven a string, rearrange all of its characters to form a palindrome. If multiple palindromic rearrangements are possible, return the lexicographically smallest one.
A palindrome reads the same from left to right and right to left.
If no palindromic rearrangement exists, return an empty string.
You must use every character exactly as many times as it appears in the input.
s consisting of lowercase English letters.s exactly once each.s contains only lowercase English letters.Example 1
Input
s = "aabb"
Output
"abba"
Explanation
Two palindromes are possible: "abba" and "baab". The lexicographically smallest is "abba".
Example 2
Input
s = "bbaa"
Output
"abba"
Explanation
The same multiset of characters can be rearranged into the smallest palindrome "abba".
Example 3
Input
s = "abc"
Output
""
Explanation
Each character appears once, so there are three odd counts. No palindrome can be formed.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.