Palindrome Number
Real-world version: Mirrored Meter ReadingThe statement here is our own: the same inputs, outputs and technique.
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 starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def is_mirrored(reading: int) -> bool:public boolean isMirrored(int reading)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's