AlgoMaster Logo

Counting Bits

n=5
0 / 12
012345000000
algomaster.io
Step:Count the 1-bits of every number from 0 to 5. Reuse earlier answers: ans[i] = ans[i & (i-1)] + 1