Carvana's inventory processing pipeline assigns integer identifiers to records. Given a non-negative integer n, return an array ans of length n + 1, where ans[i] is the number of 1 bits in the binary representation of i.
Design an algorithm that computes all values efficiently instead of converting every integer to a binary string and counting characters.
Implement count_bits(n), where the input is an integer n and the output is a list of integers. The value at index i must equal the population count, or number of set bits, in i for every 0 <= i <= n.
def count_bits(n):