Merge two sorted lists into one and join the result.
Acceptance criteria
- 1.#out should show 1-2-3-4.
DSA Tutorial · Sorting
These 10 tasks go with the Sorting Algorithms You Should Know chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “Learn these to understand divide and conquer, not to use them. The built-in sort is faster than anything you will write, and knowing that is part of the answer.” .
1.Merge two sorted arraysexercise · easy · 10 min
Merge two sorted lists into one and join the result.
Passes when: #out should show 1-2-3-4.
2.Insertion sortexercise · easy · 10 min · practice plan
Sort a small array by insertion and join it.
Passes when: #out should show 1-2-3.
3.Partition around a pivotexercise · easy · 10 min · practice plan
Move values smaller than the pivot to the front and show the boundary.
Passes when: #out should show boundary 2.
4.Bubble one passexercise · easy · 10 min · practice plan
Run a single bubble pass and join the result.
Passes when: #out should show 1-3-2-5.
5.Name the stable oneexercise · medium · 10 min · practice plan
Report which of merge sort or heap sort is stable.
Passes when: #out should show merge sort.
6.Fix the merge dropping the tailbug fix · easy · 8 min
Without appending the leftovers, the longer list loses its end.
Passes when: #out should show 1-2-3-4.
7.Fix the insertion loop starting at zerobug fix · easy · 8 min · practice plan
The first element is already sorted, so the pass must start at one.
Passes when: #out should show 1-2-3.
8.Fix the partition using the wrong comparisonbug fix · medium · 8 min · practice plan
Using greater-than moves the larger values forward instead.
Passes when: #out should show boundary 2.
9.Fix the bubble pass comparing the wrong waybug fix · easy · 8 min · practice plan
Swapping when the left value is smaller sorts descending.
Passes when: #out should show 1-3-2-5.
10.Fix the claim about stabilitybug fix · easy · 8 min · practice plan
Heap sort is not stable; merge sort is.
Passes when: #out should show merge sort.
Between them these tasks cover Merge sort, Insertion sort and Partitioning.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.