Break a Palindrome
Updated
Problem 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:
- It is not a palindrome.
- It is alphabetically lower than the original palindrome.
- 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.
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
More NVIDIA interview questions
- Network Layer Execution OrderPHONE SCREEN · Seen Nov 2026
- Paged KV Cache AccessPHONE SCREEN · Seen Nov 2026
- Sliding Window Attention over a KV CachePHONE SCREEN · Seen Nov 2026
- Summarize Server Healthcheck LogsPHONE SCREEN · Seen Oct 2026
- Query a Header-Encoded MatrixOA · Seen Oct 2026
- Maximum ScoreOA · Seen Oct 2026
- Address on Same PageOA · Seen Oct 2026
- Minimize Task Resource ConsumptionOA · Seen Oct 2026
- Minimum Project Bid CostOA · Seen Oct 2026
- Count Ideal Numbers in a RangeOA · Seen Oct 2026
Similar questions at other companies
- Maximum String OperationsMicrosoft · OAMicrosoft interview questions
- Minimum No-Repeat Segments After One Character RemovalSalesforce · OASalesforce interview questions
- Longest Non-Decreasing Substring After Pair SwapsVisa · OAVisa interview questions
- Minimum Deletion Cost for Distinct Adjacent CharactersHSBC · OAHSBC interview questions
- Minimum Binary Swaps to a PalindromeAT&T · OAAT&T interview questions
- Robot Assembly Line ConflictsGoogle · OAGoogle interview questions
- Substring RemovalJP Morgan Chase · OAJP Morgan Chase interview questions
- Minimum Additions to Make a Valid ABC StringIBM · OAIBM interview questions
- Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
- Minimum Adjacent TranspositionsEpic · OAEpic interview questions