Given a palindrome-like string, replace characters so the final string is a palindrome and is lexicographically smallest among all valid results.
You are given a string s consisting of lowercase English letters. Your task is to transform it into a palindrome by changing characters as needed.
Among all palindromes that can be obtained using the minimum necessary character changes, return the lexicographically smallest one.
A palindrome reads the same from left to right and right to left.
For each mirrored pair of characters, choose the smaller character so that the resulting string stays a palindrome and is as small as possible lexicographically.
s of lowercase English letters.s under the problem rules.1 <= |s| <= $10^{5}$s contains only lowercase English letters.Example 1
Input
"egcfe"
Output
"efcfe"
Explanation
The mirrored pairs are adjusted to make the string a palindrome. Choosing the smaller character in each pair gives efcfe, which is lexicographically smallest.
Example 2
Input
"abcd"
Output
"abba"
Explanation
Make the first and last characters equal using the smaller one, and do the same for the middle pair. The smallest palindrome is abba.
Example 3
Input
"seven"
Output
"neven"
Explanation
After mirroring characters, the lexicographically smallest valid palindrome is neven. This keeps the string palindromic while minimizing the leftmost differing character.
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.