FunctionRacerProblemsRace

Nearest Mirror Number

HardMathPython, JavaScript, TypeScript, Java, C++

A mirror number reads the same from both ends, like 7, 121 or 4004. Return the mirror number closest to n that is not n itself. If two are equally close, return the smaller one. 0 counts as a mirror number.

Example 1

n 123
returns 121

121 is 2 away. The next mirror number up, 131, is 8 away.

Example 2

n 1
returns 0

0 and 2 are both 1 away, and 0 is the smaller.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Math problems