Question DSA-TP-0012
MediumWhat is the output of this code?
a = [0, 1, 0, 3, 12]
k = 0
for x in a:
if x != 0:
a[k] = x
k += 1
for i in range(k, len(a)):
a[i] = 0
print(a)
- A.
[1, 12, 3, 0, 0]
- B.
[0, 0, 1, 3, 12]
- C.
Sign up free to see the answer and a step-by-step explanation.