Question DSA-TP-0005
EasyWhat is the output of this code?
a, b = [1, 3, 5], [2, 4]
i = j = 0
out = []
while i < len(a) and j < len(b):
if a[i] <= b[j]:
out.append(a[i]); i += 1
else:
out.append(b[j]); j += 1
out += a[i:] + b[j:]
print(out)
- A.
[5, 4, 3, 2, 1]
- B.
[1, 3, 5, 2, 4]
- C.
Show answer and explanation
Answer: D
Merging two sorted lists with two pointers produces one sorted list.