A delivery van's trip odometer shows a positive whole-number distance, displayed with no leading zero. Parked overnight beside a puddle at the loading dock, the driver notices the odometer's reflection in the water: the puddle reverses the order of the digits (it mirrors the digit sequence left-to-right, it does not flip the shape of each individual digit), and, like any digital display, it never shows a leading zero — so a reflected reading such as 021 is displayed simply as 21. Given the true reading, find the absolute difference between it and its puddle reflection.
A single line containing one integer N — the true odometer reading.
A single integer: the absolute difference between N and its digit-reversed reflection.
1 <= N <= 10^9 N has no leading zeros.
Example 1
Input
1832
Expected
549
Explanation
Reversing the digits of 1832 gives 2381. The absolute difference |1832 - 2381| = 549.
Example 2
Input
100
Expected
99
Explanation
Reversing the digits of 100 gives "001", which as an integer (no leading zero shown) is 1. The absolute difference |100 - 1| = 99.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →