Break a Palindrome
Updated
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.
More AT&T Online Assessment questions
- Companies with Average Salary Above 40000OA · Seen Oct 2026
- Count Proper Prefix MatchesOA · Seen Oct 2026
- Minimum Binary Swaps to a PalindromeOA · Seen Oct 2026
- 3SumOA · Seen Oct 2025
- Advertising System Failures ReportOA · Seen Nov 2024
- Counting Triplets Divisible by DOA · Seen Nov 2024
- Project EstimatesOA · Seen Nov 2024
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
- 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
- Return Exact Cash Register ChangeBank of America · OABank of America interview questions