Bit Counts
Return a list out of length where out[i] is the number of 1 bits in the binary form of i.
Requirements
- Run in using the relation .
Examples
EXAMPLE WALKTHROUGH0 to 2
A guided view of the published example, not a trace of your code.
INPUT
[2]TASKbit_counts()
EXPECTED OUTPUT
[0,1,1]Start with the input values shown in this example.
Example 1 of 3
Input: n = 2
Output: [0,1,1]
Explanation: 0 to 2
Input: n = 5
Output: [0,1,1,2,1,2]
Explanation: 0 to 5
Input: n = 0
Output: [0]
Explanation: only zero
Hint 1
Shifting right drops the last bit; add it back with i & 1.