Count the number of '1' bits in an integer (Hamming weight).
The n &= (n-1) trick is elegant: it removes one set bit per iteration, so we loop exactly count times.
💡 Pro tip: Understand this problem deeply — don't just memorize the code. Try explaining the approach out loud as if teaching a friend. If you can explain it simply, you truly understand it!
hammingWeight(11)
3
hammingWeight(128)
1