Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Hamming Distance

Easy
bit-manipulation

The Hamming distance between two integers is the number of bit positions where they differ. Given x and y, return their Hamming distance.

Input: one line, two integers x y. Output: the Hamming distance.

Example 1
Input:
1 4
Output:
2

001 vs 100 — bits 0 and 2 differ.

Example 2
Input:
3 1
Output:
1

Constraints

  • 0 ≤ x, y ≤ 2^31 − 1
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.