Alphabetically Smallest Palindrome
Reported by candidates from IBM's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
IBM reported this one in September 2026, and the first attempt usually dies on a misread. The title says palindrome, so people reach for the classic two-pointer mirror on the string's positions. But the statement lets you rearrange the letters afterward, so position never matters. Only letter counts do. That turns it into a counting plus greedy problem with a two-pointer pass over the odd-count letters. It's short once you see it, and brutal if you don't. If you blank halfway through the live OA, StealthCoder is the invisible safety net that reads the problem and hands you the approach. Know the trick before you sit down anyway.
The problem
A palindrome reads the same from either direction; for example, ada is a palindrome. You are given a string s of lowercase English letters. Change the fewest letters possible so that the characters of s can be rearranged to form a palindrome. If multiple palindromes require the same minimum number of changes, return the alphabetically smallest one. Function makeAlphabeticallySmallestPalindrome(s: String) → String Examples Example 1 s = "azzzbbb" return = "abzbzba" Change one z to a, producing the letters in aazzbbb. They can be rearranged as abzbzba, the alphabetically smallest palindrome obtainable with one change. Example 2 s = "fhaigh" return = "afhhfa" Change i to a and g to f. The resulting pairs form the alphabetically smallest palindrome afhhfa. Constraints 1 ≤ s.length ≤ 3 × 10^5 s consists only of lowercase English letters.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Count each letter. Letters with an odd count are the problem. If k letters are odd, the minimum number of changes is floor(k/2), because one change flips the parity of two letters at once. To make the result alphabetically smallest, change the largest odd letter into the smallest odd letter. Sort the odd letters and walk two pointers inward, converting the right one to the left one. If one odd letter is left in the middle, it becomes the center. Then build the answer: half the count of each letter in sorted order, the center, then the mirror. Both examples check out this way. The common pitfall is mirroring positions in the original string, which gives wrong counts and the wrong answer. Another is forgetting the center letter. Counts run on 26 letters, so it's linear with a 3 x 10^5 input. If the pairing logic slips under pressure, StealthCoder can cover the live OA.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Alphabetically Smallest 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 passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass IBM's OA.
IBM reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Alphabetically Smallest Palindrome FAQ
What's the trick in Alphabetically Smallest Palindrome?+
Ignore positions. Count letters, find the ones with odd counts, and fix them in pairs. Each change turns a larger odd letter into a smaller odd letter, which fixes two parities at once. Then build the palindrome from sorted half-counts plus an optional center.
How many changes are actually needed?+
If k letters have odd counts, you need floor(k/2) changes. One odd letter can stay as the center, so only the extras need fixing. In the first example k is 3, so one change. In the second k is 4, so two changes.
Why not just use two pointers on the string like a normal palindrome problem?+
Because the statement lets you rearrange the characters. Mirroring positions would count changes the problem doesn't require. The two pointers belong on the sorted list of odd-count letters, not on the string itself.
How do I get the alphabetically smallest result?+
Change big odd letters into small odd letters, pairing the largest with the smallest and moving inward. After that, put half of each letter's count in sorted order on the left, add the center letter if one exists, and mirror the left half to the right.
How should I prepare for this in 48 hours?+
Write it once from scratch using a 26-slot count array. Test it on the two given examples, plus a single-character string and an all-even string. Watch the center letter and keep the build linear, since the string can be up to 3 x 10^5 long.