Trains the technique from
LeetCode 2571Minimum Operations to Reduce an Integer to 0This 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 depth gauge reads offset millimetres away from true, and a technician zeroes it with a
calibration dial. One press of the dial shifts the reading by a value that is a power of
two - 1, 2, 4, 8, 16 and upward with no cap - and the same press decides whether that value
is added to the reading or taken off it.
Presses may overshoot: the reading is free to rise past where it started or fall past zero on the way, and nothing forces the reading to shrink at every press. Calibration is finished the moment the reading is exactly 0.
Given offset, return the fewest presses that bring the reading to 0.
Example 1
Adding 1 takes the reading to 24, taking off 8 leaves 16, and taking off 16 lands on 0. Each shift is a power of two, so that is three presses.
Example 2
Taking off 2 leaves 4 and taking off 4 lands on 0, so two presses are enough.
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 gauge_presses(offset: int) -> int:public int gaugePresses(int offset)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.