Find the minimum number of single-bit flips needed to change one integer into another.
Given two integers start and goal, determine the minimum number of bit positions that must be flipped in start so that it becomes equal to goal.
A bit flip changes a 0 to 1 or a 1 to 0 at exactly one position.
Only positions where the two numbers differ need to be flipped, so the answer is the number of differing bits in their binary representations.
start and goal.start into goal.0 <= start, goal <= $10^{9}$ is a reasonable interview-style assumption.Example 1
Input
start = 10, goal = 7
Output
3
Explanation
10 = 1010 and 7 = 0111. The bits differ in three positions, so 3 flips are needed.
Example 2
Input
start = 3, goal = 4
Output
3
Explanation
3 = 0011 and 4 = 0100. All three relevant bit positions differ, so the minimum number of flips is 3.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.