Trains the technique from
LeetCode 7Reverse IntegerThis 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.
An old flow meter transmits its counter as reading, a signed whole number. The meter's firmware was wired back to front, so the decimal digits arrive in the opposite order to the one intended, and the decoder has to undo that: keep the sign as it is and read the digits the other way round. Any zeros that end up in front simply vanish, since the decoded counter is a number rather than a run of characters, so a reading of 4100 decodes to 14.
The decoder is a small board with one signed 32-bit register, so it can only ever hold a value from -2^31 through 2^31 - 1. Nothing wider is available: no 64-bit slot, no unbounded arithmetic, and no scratch buffer of characters. If the decoded counter would fall outside what the register holds, the decoder gives up and reports 0. Return the decoded counter.
Example 1
Reading the digits 8, 1, 0, 4 the other way round gives 4, 0, 1, 8.
Example 2
The digits flip to 0, 7, 5, 3 and the leading zero drops away, while the sign rides along unchanged.
Example 3
The flipped digits spell a counter above 2^31 - 1, which the register cannot hold, so the decoder reports failure.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def flip_register(reading: int) -> int:public int flipRegister(int reading)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.