Find the Closest Palindrome
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given a positive integer as a decimal string n. Return, as a string, the palindrome integer closest to it, **not counting n itself**.
"Closest" means the smallest absolute difference. If two palindromes are equally close, return the smaller one. Distances are measured between integer values, and 0 counts as a palindrome.
n can have up to 18 digits, so stepping outward one integer at a time is too slow in general. Think about which few candidates can possibly win.
Examples
Constraints
- 1 <= n.length <= 18
- `n` consists only of digits
- `n` has no leading zeros
- `n` represents an integer in the range [1, 10^18 - 1]
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.