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