You're given a palindromic string of lowercase English letters. Your mission is to break the palindrome by replacing exactly one character with any lowercase English letter, creating a string that is:
- ✅ Not a palindrome
- ✅ Lexicographically smallest possible
If it's impossible to break the palindrome (hint: think about single characters!), return an empty string.
Lexicographical order: String a comes before string b if at the first differing position, a has a smaller character. For example, "abcc" < "abcd" because 'c' < 'd' at position 3.
Example: "abccba" → "aaccba" (replace first 'b' with 'a')
Input & Output
Visualization
Time & Space Complexity
For each of n positions, we try 26 letters and check if result is palindrome (O(n)), giving us O(n × 26 × n) = O(n²)
We create new strings for each attempt, each taking O(n) space
Constraints
- 1 ≤ palindrome.length ≤ 1000
- palindrome consists of only lowercase English letters
- palindrome is guaranteed to be a valid palindrome