For every number i in [0, n], count the number of 1-bits. Return as an array.
This gives O(n) time vs O(n log n) if we count bits for each number individually.
💡 Pro tip: Understand this problem deeply — don't just memorize the code. Try explaining the approach out loud as if teaching a friend. If you can explain it simply, you truly understand it!
countBits(5)
[0, 1, 1, 2, 1, 2]