Break a Palindrome
Learn this problemProblem statement
You are given a lowercase string palindrome that is a palindrome. Change exactly one character so that the result is not a palindrome.
Among all valid results, return the lexicographically smallest one. If changing exactly one character cannot produce a non-palindrome, return "IMPOSSIBLE".
Two strings of the same length are compared lexicographically by the first position at which they differ.
Function
breakPalindrome(palindrome: String) → StringExamples
Example 1
palindrome = "abccba"return = "aaccba"Changing the first non-'a' character in the left half gives the smallest possible non-palindrome.
Example 2
palindrome = "a"return = "IMPOSSIBLE"Every one-character string is a palindrome, so no one-character change can make it non-palindromic.
Example 3
palindrome = "aa"return = "ab"The left character is already 'a'; changing the final character to 'b' gives the smallest valid result.
Example 4
palindrome = "aba"return = "abb"Changing the middle character would preserve the palindrome, so the smallest valid choice is to change the final character to 'b'.
Constraints
1 <= palindrome.length <= 100000palindromecontains lowercase English letters.palindromeis a palindrome.- You must change exactly one character.