JuniorMath

Mirror Distance of an Integer

You are given an integer n.

Define its mirror distance as abs(n - reverse(n)), where reverse(n) is the integer formed by reversing the digits of n.

Return an integer denoting the mirror distance of n.

abs(x) denotes the absolute value of x.

Example 1
Inputn = 25
Output27
reverse(25) = 52, so the answer is abs(25 - 52) = 27.
Example 2
Inputn = 10
Output9
reverse(10) = 01, which is 1, so the answer is abs(10 - 1) = 9.

Constraints

  • 1 <= n <= 10^9

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate