Merge two sorted lists
Merge two sorted integer lists into a fresh sorted list, retaining duplicates. Do not sort the combined list.
left, right = [1, 3], [2, 4]
print(left[0] <= right[0])Reason about the state
Compare the first unconsumed values, append the smaller and advance only that pointer. Append the remaining suffix when one input ends. Before writing code, identify what each variable means after one iteration. Walk through the example and explain why the next transition preserves that meaning. Then check the smallest permitted input and a case with repeated values. A correct answer follows the contract for every input, including the boundary cases in the checks. Keep any input mutation within the stated rules; return a fresh result when the task asks for one.
Your task
Merge two sorted integer lists into a fresh sorted list, retaining duplicates. Do not sort the combined list.
The explanation opens here once every check passes.