Break a Palindrome
Reported by candidates from AT&T's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The AT&T OA reported in October 2025 hands you a palindrome and asks you to ruin it as cheaply as possible. Strip the wording and it's a greedy scan over half the string, nothing more. One pass, one swap, one edge case. If you blank on the edge case, StealthCoder is the safety net running invisibly during the live assessment, but the logic here is small enough to hold in your head. You need to know where to look and what to do when there's nothing to change. That's the whole problem, and it fits in about ten lines.
The problem
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) → String Examples 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. palindrome contains only lowercase English letters. palindrome is a palindrome.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: to get the lexicographically smallest result, make the earliest possible position smaller. Scan only the first half, from index 0 to n/2 - 1. The first character that isn't 'a' becomes 'a'. That breaks symmetry because its mirror still holds the original letter. If the whole first half is 'a', every lowering option is gone, so change the last character to 'b'. That's the 'aa' to 'ab' case. Length 1 returns the empty string. The classic pitfall is scanning the full string. For odd lengths, the middle character mirrors itself, so changing it to 'a' keeps the string a palindrome. Stopping at n/2 handles that. Another miss is forgetting the n == 1 check. Complexity is O(n) time and O(n) space for the char array. If your mind goes blank mid-assessment, StealthCoder can surface the solution live, but you can own this one in a few minutes.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Break a Palindrome cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as break a palindrome. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass AT&T's OA.
AT&T reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Break a Palindrome FAQ
What's the trick in Break a Palindrome?+
Greedy on the first half. Find the first character that isn't 'a' and replace it with 'a'. If every character in the first half is 'a', change the last character to 'b'. Return an empty string for length 1.
Why only scan the first half of the string?+
The string is a palindrome, so the second half mirrors the first. Changing a first-half character breaks symmetry. In an odd-length string the middle character mirrors itself, so changing it keeps the string a palindrome and gets you nothing.
How hard is this one really?+
Easy to medium. The logic is short, but the edge cases trip people up: length 1, all-'a' strings, and odd-length middles. Once you see the greedy rule, the code is about ten lines.
Why change the last character to 'b' and not something else?+
If the first half is all 'a', nothing can be lowered. You must raise something, and the smallest result comes from changing the last character, since it has the least lexicographic weight. 'b' is the smallest letter above 'a'.
How do I prep for this in 48 hours?+
Write it from scratch twice and test 'a', 'aa', 'aba', 'aaa', and 'abccba'. Those cover every branch. Then do a couple of other greedy string problems so the pattern feels automatic.