Question DSA-BIT-0064
HardWhat is the output of this code?
def count_bits(n):
d = [0] * (n + 1)
for i in range(1, n + 1):
d[i] = d[i >> 1] + (i & 1)
return d
print(count_bits(8))
- A.
[0, 1, 1, 2, 1, 2, 2, 3, 1]
- B.
[0, 1, 2, 3, 4, 5, 6, 7, 8]
- C.
Sign up free to see the answer and a step-by-step explanation.