Talentd
FleetCode

3783. Mirror Distance of an Integer

Easy91.5% acceptance2 companies

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:

Input: n = 25

Output: 27

Explanation:

  • reverse(25) = 52.
  • Thus, the answer is abs(25 - 52) = 27.

Example 2:

Input: n = 10

Output: 9

Explanation:

  • reverse(10) = 01 which is 1.
  • Thus, the answer is abs(10 - 1) = 9.

Example 3:

Input: n = 7

Output: 0

Explanation:

  • reverse(7) = 7.
  • Thus, the answer is abs(7 - 7) = 0.

Constraints:

  • 1 <= n <= 109

Asked at 2 companies

Topics

Hints open one at a time

Hint 1
Simulate as described
7:57
Still stuck?Read the written solution, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def mirrorDistance(self, n: int) -> int:
3
Starter codePython 3Spaces: 4
Examples
Input
25
Input
10
Input
7
Your code is saved on this device.Solution