Trains the technique from
LeetCode 1009Complement of Base 10 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.
A meter reading n is held in binary with no leading zeros, so the reading 5 is held as 101.
Flipping the reading turns every 0 into a 1 and every 1 into a 0, across exactly the bits the reading is held in. Flipping 101 gives 010, which is the reading 2.
Return the reading that flipping produces. The reading 0 is held as the single bit 0, so flipping it gives 1.
Example 1
The reading 2 is held as 10. Flipping every bit gives 01, which is the reading 1.
Example 2
The reading 8 is held as 1000, and flipping every bit gives 0111.
Example 3
The reading 0 is held as the single bit 0, and flipping that bit gives 1.
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_reading(n: int) -> int:public int flipReading(int n)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.