Break a Palindrome
Learn this problemProblem statement
A palindrome reads the same forwards and backwards, like "mom". Modify a palindrome by changing exactly one character to another character within the ASCII range [a-z]. The goal is to ensure the new string fulfills the following criteria:
Return the new string, or "IMPOSSIBLE" if it is not feasible to create such a string.
Function
breakPalindrome(palindromeStr: String) → String
Complete the function breakPalindrome in the editor with the following parameter(s):
- string palindromeStr: the input string
Returns
string: the resulting string, or IMPOSSIBLE if one cannot be formed
Examples
Example 1
palindromeStr = "aaabbaaa"return = "aaaabaaa"Possible strings lower alphabetically than 'aaabbaaa' after one change are ['aaaabaaa', 'aaabaaaa']
'aaaabaaa' is not a palindrome and is the lowest string that can be created from palindromeStr.
Constraints
- 1 ≤ length of palindromeStr ≤ 1000
- palindromeStr is a palindrome
- palindromeStr contains only lowercase English letters