Trains the technique from
LeetCode 453Minimum Moves to Equal Array ElementsThis 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 rack carries n pressure gauges, and offsets[i] is the signed zero-offset of gauge i measured in ticks. An offset can sit below zero.
A pulse singles out one gauge and lifts the offset of every gauge except that one by exactly one tick. The singled-out gauge is untouched.
Return the fewest pulses that leave all n offsets reading the same value. The answer always fits in a signed 32-bit integer.
Example 1
Eight pulses can settle the rack at 12: gauge 1 is the singled-out gauge on 3 of them, gauge 2 on the other 5, and gauge 0 on none. Gauge 0 is lifted all 8 times to 12, gauge 1 is lifted 5 times to 12, and gauge 2 is lifted 3 times to 12.
Example 2
Both offsets already read the same value, so no pulse is needed.
Example 3
Nineteen pulses can settle the rack at 14, with gauge 0 singled out on none of them, gauge 1 on 5 of them, and gauges 2 and 3 on 7 each. Offsets may start below zero, as gauge 0 does here.
Example 4
A rack of one gauge is already uniform, so the count is zero.
Example 5
Five pulses can settle the rack at 8, with gauge 0 singled out on every one of them, so only gauge 1 is ever lifted.
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 min_moves(offsets: list[int]) -> int:public int minMoves(int[] offsets)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.