The Hamming distance between two non-negative integers is the number of bit positions at which their binary representations differ.
One line: two non-negative integers a and b.
One line: the Hamming distance between a and b.
Example 1
Input
1 4
Expected
2
Explanation
1 is 001 and 4 is 100; they differ in two bit positions, so the distance is 2.
Example 2
Input
7 7
Expected
0
Explanation
Identical numbers differ in no bits, so the distance is 0.
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 →