Shortest Palindrome
A hard-tier problem at 41% community acceptance, tagged with String, Rolling Hash, String Matching. Reported in interviews at Pocket Gems and 4 others.
Shortest Palindrome is a hard string problem that shows up in OAs at Google, Visa, eBay, and others. The setup is deceptively simple: given a string, find the minimum number of characters to prepend so the result reads the same forwards and backwards. Most candidates start with a brute force or substring-matching approach and run into TLE. The trick isn't obvious without seeing the pattern first. If this problem hits your live assessment and you blank on the algorithm, StealthCoder surfaces a working solution in seconds while the proctor sees nothing.
Companies that ask "Shortest Palindrome"
Shortest Palindrome is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know.
Get StealthCoderThe naive approach, checking every possible prepend length with palindrome validation, times out. The real insight uses Rolling Hash or KMP-style String Matching: you can frame this as finding the longest palindromic prefix of the original string, then prepend the reverse of the remaining suffix. A hash-based approach builds a rolling hash of the string in both directions and finds the longest overlap point where the forward hash equals the reverse hash. KMP String Matching offers another angle: concatenate the string with a delimiter and its reverse, then use the KMP failure function to find the longest palindromic prefix. Both avoid quadratic substring checks. Most candidates who've drilled the pattern solve it cleanly. If you haven't seen Rolling Hash or String Matching applied this way, StealthCoder is your safety net during the timed assessment.
Pattern tags
You know the problem.
Make sure you actually pass it.
Shortest Palindrome recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Shortest Palindrome interview FAQ
Is this really asked at FAANG?+
Yes. Google and other top companies in the input data ask it. It's a hard problem with a 40% acceptance rate, so it filters well. If you see it live, most candidates either know the pattern or struggle badly. No middle ground.
What's the trick I'm missing?+
Stop checking every prepend length. Instead, find the longest palindromic prefix using Rolling Hash or KMP String Matching. Once you have that, the answer is just the length of the non-palindromic suffix. The trick is reframing the problem, not brute force validation.
How do Rolling Hash and String Matching relate here?+
Both avoid substring-by-substring palindrome checks. Rolling Hash compares forward and reverse hashes to find the palindrome boundary in one pass. KMP uses the failure function on a concatenated string. Either works. Hash is often faster in practice, but KMP is deterministic if hash collisions worry you.
Will I see this without drilling String Matching first?+
Unlikely to solve it under time pressure. The problem requires knowledge of Rolling Hash or KMP as a prerequisite. If String Matching isn't in your prep, this becomes a trap that burns 20 plus minutes.
How common is Shortest Palindrome in actual OAs?+
Moderate frequency across the companies listed. It's hard enough to be a differentiator but not so obscure that top candidates haven't seen it. If you hit it unprepared, it's a real risk to your score.
Want the actual problem statement? View "Shortest Palindrome" on LeetCode →