← Bit Manipulation

Pattern Recognition Drill

#87 — Hamming distance

Easy Bit Manipulation

The Problem

Count positions where corresponding bits of two integers differ.

What approach would you use?

Think about it before scrolling down.

Key Signals

Bit Manipulation

XOR a and b, count set bits in the result. Combines XOR + Kernighan's trick. O(1).

Common Trap

This is a two-step pattern: XOR to find differences, then count bits.

← #86 #88 →