All problems
0927EasyMath

Gap to the Mirrored Number

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3783Mirror Distance of an Integer

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def mirror_distance(n: int) -> int:
Java
public int mirrorDistance(int n)
September 7
Apply