Break a Palindrome
Problem statement
You are given a palindromic string palindrome containing only lowercase English letters.
Replace exactly one character with another lowercase English letter so that the resulting string is not a palindrome. Return the lexicographically smallest result that can be obtained. If no valid result exists, return the empty string.
Function
breakPalindrome(palindrome: String) → StringExamples
Example 1
palindrome = "abccba"return = "aaccba"Changing the first non-a character in the first half to a produces the smallest non-palindrome.
Example 2
palindrome = "a"return = ""Every one-character string is a palindrome, so no valid replacement exists.
Example 3
palindrome = "aa"return = "ab"No character in the first half can be lowered, so changing the last character to b yields the smallest valid result.
Constraints
1 <= palindrome.length <= 1000.palindromecontains only lowercase English letters.palindromeis a palindrome.