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