Question DSA-ARR-0016
HardWhat is the output of this code?
a = [2, 0, 2, 1, 1, 0]
lo, mid, hi = 0, 0, len(a) - 1
while mid <= hi:
if a[mid] == 0:
a[lo], a[mid] = a[mid], a[lo]; lo += 1; mid += 1
elif a[mid] == 1:
mid += 1
else:
a[mid], a[hi] = a[hi], a[mid]; hi -= 1
print(a)
- A.
[0, 1, 0, 1, 2, 2]
- B.
[0, 0, 1, 1, 2, 2]
- C.
Sign up free to see the answer and a step-by-step explanation.