Merge Ascending and Descending
up is sorted in non-decreasing order and down is sorted in non-increasing order (largest first). Return one list in non-decreasing order holding every item of both lists. Repeats are kept: if a value appears three times across the two lists, it appears three times in the answer.
Either list may be empty. Do not change the inputs.
Example 1
up [1,4,9]
down [8,5,2]
returns [1,2,4,5,8,9]
Reversing down gives 2, 5, 8; merging it with 1, 4, 9 gives the sorted list.
Example 2
up [2,2]
down [3,2,0]
returns [0,2,2,2,3]
Three 2s in total, all kept.
Constraints
0 <= len(up), len(down) <= 50-1000 <= up[i], down[i] <= 1000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.