Reported March 2024
Amazontwo pointers

Lexicographically Smallest Palindrome Possible

Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Amazon OA. Under 2s to a working solution.
Founder's read

Amazon's March OA threw this at candidates: build the lexicographically smallest palindrome possible. You've got a string, and you need to rearrange it into a palindrome that comes first alphabetically. Two-pointer logic is the skeleton, but the real trick is understanding how character frequency and positioning interact. If you blank on the rearrangement strategy during the live OA, StealthCoder reads the problem and feeds you the approach in seconds, so you're never stuck guessing.

Pattern and pitfall

The pattern is two-pointers plus greedy placement. Count character frequencies first. For a palindrome, you can have at most one character with odd count (it goes in the middle). Then use two pointers moving inward from both ends of your result string: place the smallest available characters on the left and right simultaneously, preserving lexicographic order. The greedy choice is always to pick the smallest character that still allows a valid palindrome. Common pitfall: forgetting to check if a palindrome is even possible, or placing characters without considering the lexicographic constraint. StealthCoder handles the character-frequency bookkeeping and pointer logic in real time, so if you're unsure whether to place a character on the left or middle, you've got the safety net.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Lexicographically Smallest Palindrome Possible 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as shortest palindrome. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Amazon's OA.

Amazon reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Lexicographically Smallest Palindrome Possible FAQ

What does 'lexicographically smallest' mean here?+

It means the result string should come first in alphabetical order. So 'aba' beats 'baa'. During rearrangement, always try to place smaller characters on the outside (left and right edges) rather than in the middle.

Can every string be rearranged into a palindrome?+

No. Count each character's frequency. If more than one character has an odd count, a palindrome is impossible. If zero or one character has odd count, you can build one. Check this first to avoid wasting time.

How do I handle the middle character if the string is odd length?+

The character with an odd count (if one exists) goes in the middle. Use the remaining pairs symmetrically on both sides. Greedy placement still applies: smallest characters on the left and right edges.

Is this problem still asked, or has Amazon moved on?+

This exact variant was reported in March 2024. Amazon rotates OA problems, but two-pointer palindrome logic remains a core pattern. Even if the exact wording changes, the underlying approach is stable.

Can I solve this in 48 hours if I've never seen it?+

Yes. Understand character frequency first, then the two-pointer mirror logic. Build a small example by hand (e.g., 'aabbc' to 'abcba'). That intuition carries you through the code. You don't need fancy techniques here.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Amazon.

OA at Amazon?
Invisible during screen share
Get it