Reported November 2024
Amazonhash table

Min Chars to Append

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 November OA included this classic string-manipulation problem: given a string, find the minimum number of characters you need to append to make it a palindrome. You're not rearranging or inserting in the middle, just adding to the end. It feels like a greedy problem at first, but it's a trap. The real pattern is KMP or rolling hash to detect the longest palindromic prefix that uses the entire string as its pivot. StealthCoder will catch the moment you realize you need to check all prefixes, not just try to match character-by-character.

Pattern and pitfall

The trick: you're looking for the longest suffix of the string that is also a palindrome starting from index 0. In other words, find the longest palindromic prefix, then append the reverse of the remaining characters. Naive checking each prefix is O(n2). The move is KMP on the string concatenated with its reverse, separated by a delimiter, or rolling hash for faster palindrome detection. Most candidates try greedy matching from the end and miss the need to validate the entire structure. That's where the problem bites. StealthCoder helps you stay grounded: confirm you're checking prefix-palindromes correctly before you code the full solution.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Min Chars to Append 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. If you're reading this with an OA window open, you're who this was built for.

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. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Min Chars to Append FAQ

Is this just matching characters backward from the end?+

No. You need to verify that when you remove characters from the front, what remains forms a valid palindrome with the original string. Naive character matching will fail on strings like 'aab' where you need to append 'ba', not just 'b'.

Can I solve this in one pass without checking all prefixes?+

Not safely. You need to identify the longest palindromic prefix in the full string. KMP or rolling hash are standard approaches. One pass won't reliably give you the answer, and Amazon interviewers will push back.

How do I apply KMP here?+

Build the KMP failure function on 'string + # + reverse(string)'. The final failure value tells you the longest palindromic prefix. Then append the reverse of what's left. It's O(n) once you set it up.

What's the difference between this and a standard palindrome check?+

You're not just checking if it's a palindrome. You're finding the longest palindrome that starts at index 0, then computing the cost to extend it to the full string. The key insight is that you're appending to make the entire result a palindrome, not trimming.

Will brute force pass the time limit?+

Probably not if n is large (500+). O(n2) or O(n3) string operations will time out. Implement KMP or rolling hash. Amazon expects you to know the optimization.

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