Classic problem #3783EasyMath
Mirror Distance of an Integer
Real-world version: Gap to the Mirrored NumberTracked in this browser only
Read Mirror Distance of an Integer on LeetCode(opens in a new tab)
The statement here is our own: the same inputs, outputs and technique.
Reading the digits of n in the opposite order gives another whole number, dropping any leading zeros that appear.
Return how far apart the two numbers are.
Examples
Example 1
- Input
- n = 4213
- Output
- 1089
Reading the digits the other way gives 3124, and 4213 less 3124 is 1089.
Example 2
- Input
- n = 200
- Output
- 198
The digits read backwards give 002, which is the number 2, so the gap is 198.
Example 3
- Input
- n = 1221
- Output
- 0
The number reads the same either way, so the gap is nothing.
Constraints
- 1 <= n <= 10^9
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
Python
def mirror_distance(n: int) -> int:Java
public int mirrorDistance(int n)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 11 test cases: 11 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's