Smallest Palindromic Rearrangement I - Problem
You are given a palindromic string s. Return the lexicographically smallest palindromic permutation of s.
A palindromic string reads the same forward and backward. A lexicographically smaller string is one that would appear earlier in dictionary order.
Since the input is already a palindrome, we need to find the smallest possible rearrangement that maintains the palindromic property.
Input & Output
Example 1 — Basic Rearrangement
$
Input:
s = "aabcc"
›
Output:
"acbca"
💡 Note:
The input "aabcc" can be rearranged to form "acbca" which is a palindrome. This is the lexicographically smallest palindromic permutation possible.
Example 2 — Already Optimal
$
Input:
s = "abc"
›
Output:
"abc"
💡 Note:
The string "abc" is already a palindrome and in its lexicographically smallest form, so we return it as is.
Example 3 — Single Character
$
Input:
s = "a"
›
Output:
"a"
💡 Note:
A single character is always a palindrome and is already in its smallest form.
Constraints
- 1 ≤ s.length ≤ 1000
- s consists of lowercase English letters
- s is guaranteed to be a palindrome
Visualization
Tap to expand
Understanding the Visualization
1
Input
Given palindromic string with characters to rearrange
2
Process
Sort characters and build palindrome symmetrically
3
Output
Lexicographically smallest palindromic permutation
Key Takeaway
🎯 Key Insight: Sort all characters first, then build the palindrome symmetrically to guarantee the lexicographically smallest result
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code