NewThe Learning module is now liveSee what's new

Given a symmetric string s, rearrange the characters and find the smallest lexicographical palindrome possible.

A palindrome is a string that reads the same backward as forward. The smallest lexicographical palindrome is the one that appears first in dictionary order among all possible palindromic arrangements of the characters in the string.

Constraints:

  • 1 <= s.length <= 10510^5
  • s consists of lowercase English letters.

Example 1:

Input: s = "cbcacbc" Output: "bccaccb" Explanation: The input string has the characters 'c', 'b', and 'a' with counts 4, 2, and 1 respectively. To form the smallest lexicographical palindrome:

  • Arrange 'a' in the middle since it has an odd count.
  • Place 'b's and 'c's symmetrically around 'a'.
  • The resulting palindrome is "bccaccb".

Example 2:

Input: s = "babab" Output: "abbba"

Example 3:

Input: s = "yxxy" Output: "xyyx"


Accepted
939/1.9k
Acceptance Rate49.6%
Test Cases
Input
s =
Output
Expected