Trains the technique from
LeetCode 2220Minimum Bit Flips to Convert NumberThis 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.
Two banks of switches are described by the whole numbers start and goal. A switch is on wherever the number carries a 1 bit, switches are numbered from the lowest bit upwards, and any place beyond a number's own bits counts as off.
One throw flips a single switch. Return the fewest throws that turn the start bank into the goal bank.
Example 1
The lowest four switches are on in the first bank and off in the second, and the next four are the other way round, so all eight have to be thrown.
Example 2
The first bank has its lowest ten switches on while the second has only the eleventh, so ten switches go off and one comes on.
Example 3
The two banks already match, so nothing is thrown.
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_bit_flips(start: int, goal: int) -> int:public int minBitFlips(int start, int goal)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.