AMAZON & MICROSOFT Question – Solved

10 Live
Break a Palindrome 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: 1.It is not a palindrome. 2.It is alphabetically lower than the original palindrome. 3.It is the smallest possible string alphabetically that can be obtained by changing just one character. Return the new string, or "IMPOSSIBLE" if it is not feasible to create such a string. Example: palindromeStr = 'aaabbaaa' * 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. Function Description Complete the function breakPalindrome in the editor with the following parameter: string palindromeStr: the original string Returns: string: the resulting string, or "IMPOSSIBLE" if one cannot be formed.

Asked in: AMAZON MICROSOFT

Image of the Question

Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| Given an n x m grid, where rows are numbered from 7 to n and columns from 1 to … |
| There are 'N' coders standing in a line, where i denotes the ith position of a … |
| A birthday party was attended by N number of kids, and each kid was given a uni… |
| Given a matrix of size m * n, where m denotes the number of rows (starting with… |
| A traveler is traveling from the city of Zeta to Omega. He starts with X amount… |
| As an operations engineer at Amazon, you are responsible for organizing the dis… |