All problems
0050EasyMath

Mirrored Meter Reading

Tracked in this browser only
Write code

Trains the technique from

LeetCode 9Palindrome Number

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.

A two-way flow meter shows one signed whole number, reading. Flow drawn off the main drives the counter up and flow pushed back into the main drives it down, so the display can sit below zero.

The control room marks a reading as mirrored when its digits run the same way in both directions: sweeping the display from the left gives the same digit sequence as sweeping it from the right. The minus sign is printed only at the leading edge of the display and never at the trailing edge, so anything below zero cannot be mirrored. A reading of one digit, zero included, is mirrored.

Return true for a mirrored reading, false for anything else.

The meter firmware ships without any text handling, so your routine has to work on the number arithmetically. Converting the reading into characters and inspecting them is not available to you.

Examples

Example 1

Input
reading = 4884
Output
true

Sweeping left to right gives 4, 8, 8, 4 and sweeping the other way gives the same sequence.

Example 2

Input
reading = -717
Output
false

The digits alone would match, but the minus sign sits only at the leading edge, so the display cannot read alike in both directions.

Example 3

Input
reading = 250
Output
false

From the right the digits run 0, 5, 2, which is not the sequence 2, 5, 0.

Constraints

  • -2^31 <= reading <= 2^31 - 1
  • No conversion of the reading to a string is permitted

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 is_mirrored(reading: int) -> bool:
Java
public boolean isMirrored(int reading)
September 7
Apply