Given a positive integer n, write a function that returns the number of set bits it has (also known as Hamming weight).
Input: n = 11
Output: 3
Explanation: 11 in binary is 1011 (3 set bits)
Topics: bit-manipulation
Asked by: Apple, Microsoft
Time complexity: O(set bits). Space complexity: O(1).