Nearest Mirror Number
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
1 <= n <= 10**14
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Math problems
- Numbers a Broken Keypad Can TypeHard
- Smallest Factorial With K ZerosHard
- Times a Digit Is WrittenHard
- Ways as a Run of NumbersHard
- Alternating Digit SumBeginner
- Armstrong NumberBeginner
- Base K to DecimalBeginner
- Collatz StepsBeginner