You're given a string s consisting of lowercase English letters. Your mission is to transform it into a palindrome using the minimum number of character replacements possible.
Here's the twist: if multiple palindromes can be created with the same minimum operations, you must choose the lexicographically smallest one (the one that would appear first in a dictionary).
What makes a string lexicographically smaller?
String a is lexicographically smaller than string b if at the first position where they differ, a has a letter that comes earlier in the alphabet.
Goal: Return the lexicographically smallest palindrome that requires the minimum number of operations.
Example: "abcd" โ "abba" (2 operations: change 'c' to 'b' and 'd' to 'a')
Input & Output
Constraints
- 1 โค s.length โค 105
- s consists of lowercase English letters only
- Follow-up: Can you solve this in O(n) time with O(1) extra space?