#2697
Lexicographically Smallest Palindrome
newbie · 170 · lc easy +15 · verified · 80.9% accepted · 408 likes · top 92%
Description
You are given a lowercase string s. In a single operation you may replace any character with any other lowercase letter. Use the fewest operations to make s a palindrome; among all minimum-operation palindromes return the lexicographically smallest one.
Example 1:
Input: s = "egcfe"
Output: "efcfe"
Explanation: The minimum number of operations to make "egcfe" a palindrome is 1, and the lexicographically smallest palindrome string we can get by modifying one character is "efcfe", by changing 'g'.
Example 2:
Input: s = "abcd"
Output: "abba"
Explanation: The minimum number of operations to make "abcd" a palindrome is 2, and the lexicographically smallest palindrome string we can get by modifying two characters is "abba".
Example 3:
Input: s = "seven"
Output: "neven"
Explanation: The minimum number of operations to make "seven" a palindrome is 1, and the lexicographically smallest palindrome string we can get by modifying one character is "neven".
Code
1
2
3