← Quiz: Merge Sort and Quick Sort: all 13 questions
Quiz: Merge Sort and Quick Sort · Question 9 of 13
What does this print? (code)
What does this print?
def merge(a, b):
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
return out + a[i:] + b[j:]
print(merge([1, 4, 7], [2, 3, 9]))
- A.[1, 4, 7, 2, 3, 9]
- B.[1, 2, 3, 4, 7, 9]
- C.[1, 2, 3, 4, 7]
- D.[2, 3, 9, 1, 4, 7]
Answer & explanation
Correct answer: [1, 2, 3, 4, 7, 9]
The two pointers always take the smaller front item; the leftover 9 is added at the end.
Can you get the rest right without peeking?
Take the timed Quiz: Merge Sort and Quick Sort quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →