A firmware image is stored as a non-negative integer. Flashing rewrites it bit by bit: one operation flips a single bit (0 to 1 or 1 to 0). Given the current image a and the desired image b, report the minimum number of single-bit flips needed to transform a into b.
Line 1: two space-separated non-negative integers a and b.
A single integer: the minimum number of bit flips (the number of bit positions at which a and b differ).
Example 1
Input
4 7
Expected
2
Explanation
4 is 100, 7 is 111; they differ in the low two bits, so 2 flips are needed.
Example 2
Input
0 0
Expected
0
Explanation
The images are already identical, so no flips are needed.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →