HARDasked at 2 companies

Find the Closest Palindrome

A hard-tier problem at 32% community acceptance, tagged with Math, String. Reported in interviews at Yelp and 1 others.

Founder's read

Find the Closest Palindrome is a hard-tier problem that shows up in Yelp and Uber assessments. It's the kind of problem that kills candidates because the brute-force approach (iterate nearby numbers, check if palindrome) times out immediately on large inputs. You need to construct the candidate palindromes mathematically rather than search for them. With a 32% acceptance rate, most people either miss the construction trick or don't optimize the candidate generation. If this problem hits your live OA and you blank on the pattern, StealthCoder solves it in seconds, invisible to the proctor.

Companies asking
2
Difficulty
HARD
Acceptance
32%

Companies that ask "Find the Closest Palindrome"

If this hits your live OA

Find the Closest 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. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code.

Get StealthCoder
What this means

The core trick is that you don't search for the closest palindrome. Instead, you generate exactly the candidates that could possibly be closest: the palindrome formed by mirroring the first half, the palindrome formed by incrementing the middle and mirroring, the palindrome formed by decrementing the middle and mirroring, and the edge cases (10^n - 1 and 10^n + 1). Then you compare distances and return the right one. Most candidates waste time on string manipulation or try a linear search. The math topic signals that you need number theory or construction, not brute force. Common pitfall: handling single-digit numbers, negative numbers, and the case where the input itself is a palindrome (you must return a different one). String operations are just for parsing and building candidates. If you hit this in an assessment and the construction pattern doesn't click, StealthCoder delivers the working solution in real time.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Find the Closest 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. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Find the Closest Palindrome interview FAQ

Is brute force (check every nearby number) fast enough?+

No. On large inputs like 99999, you'd check hundreds of numbers. The 32% acceptance rate includes timeouts from exactly this mistake. You must construct candidate palindromes mathematically: mirror the first half, increment/decrement the middle, and check edge cases (999..., 100...01). This reduces candidates from potentially thousands to about 5.

Do I need to handle negative numbers?+

Input constraints vary, but assuming positive integers, focus on single digits (1-9 are edge cases), numbers like 10, 100, 1000, and the mirroring logic. If the input is itself a palindrome (like 121), you must return a different palindrome. Check constraints in the live assessment.

What's the difference between mirroring and incrementing the middle?+

Mirroring copies the first half to the second half. If the result equals the input, try incrementing the middle digit(s) and mirroring again, or decrementing and mirroring. This generates the two nearest palindromes on either side of the input. One will be closest.

Why are 10^n - 1 and 10^n + 1 edge cases?+

999...9 (all 9s with n digits) and 100...001 (1 followed by 0s and 1, with n+1 digits) are the closest palindromes to powers of 10. For example, closest to 1000 is either 999 or 1001. You must check these explicitly or miss the answer.

Is this problem still asked at Yelp and Uber?+

Yes, both companies appear in reports for this problem. At 32% acceptance, it's not trivial, but it's a classic construction problem. If you see it in the wild, you need the mirroring and candidate-generation approach. Study cases like 99, 101, 1000, 1221.

Want the actual problem statement? View "Find the Closest Palindrome" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.