dsa · easy
Hamming Distance
The distance between two non-negative integers x and y is the number of bit positions at which their binary writings differ (pad the shorter one with leading zeros so the widths match). Return that distance.
Example
x = 3, y = 1.
3 is 11, 1 is 01. The low bit matches (1 vs 1); the next bit differs (1 vs 0). Distance 1.
x = 7, y = 0: 7 is 111, 0 is 000 → every one of the three low bits differs → 3.
x = 0, y = 0 → 0.
## Arguments - x — first non-negative integer - y — second non-negative integer
Constraints
0 <= x, y <= 2^31 - 1
Examples
Example 1
Input: 3 1 Expected: 1
Example 2
Input: 7 0 Expected: 3
Example 3
Input: 0 0 Expected: 0