Easy · Math
Count Set Bits in Number
Given an integer n, return the number of 1 bits in its binary representation; a negative n is counted in its 64-bit two's-complement form (so -1 has 64).
Examples
Example 1
n = 13 (1101)Output: 3 set bits
Example 2
n = 23 (10111)Output: 4 set bits
Rebuild it in the studio
Core interview problems are free with a full runner and lessons; Pro opens the complete library.