Description

A bit flip of a number x is choosing a bit in the binary representation of x and flipping it from either 0 to 1 or 1 to 0. Return the minimum number of bit flips to convert start to goal.

Examples

Input:start = 10, goal = 7
Output:3
Explanation:

1010 -> 0111 needs 3 flips.

Input:start = 0, goal = 0
Output:0
Explanation:

Both numbers are already equal, so no bit flips are needed.

Input:start = 15, goal = 8
Output:3
Explanation:

Binary: 1111 -> 1000. Need to flip bits at positions 0, 1, and 2 (rightmost bits), so 3 flips total.

Constraints

  • 0 ≤ start, goal ≤ 10⁹

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!