Counting Bits

For each integer i from 0 to n, compute the number of set bits (popcount) in its binary representation. Return an array of length n+1 where the i-th element is the popcount of i.

Examples
Input: 2
Output: [0,1,1]
Hints
Related Problems

Counting Bits

For each integer i from 0 to n, compute the number of set bits (popcount) in its binary representation. Return an array of length n+1 where the i-th element is the popcount of i.