Skip to contentKEEP THE CRAFTTHE SANCTUARY

Merge Two Ordered Runs

Merge two sorted lists into one sorted list in a single pass.

The problem

Implement merge_ordered_runs(left, right). Both lists are sorted in nondecreasing order. Return one sorted list that contains every value from both lists, keeping duplicates. For example, [1, 4, 7] and [2, 3, 8] give [1, 2, 3, 4, 7, 8], and [1, 2, 2] and [2, 3] give [1, 2, 2, 2, 3]. Do not call sorted(); build the result in one pass over the two lists. Either list may be empty.

Starter code

def merge_ordered_runs(left, right):
    pass

Public examples

  1. left = [1, 4, 7], right = [2, 3, 8]gives[1, 2, 3, 4, 7, 8]
  2. left = [1, 2, 2], right = [2, 3]gives[1, 2, 2, 2, 3]

Solving it in the practice book needs an active paid plan.

Open it in the practice book
One thought at a time.