Ctrl K

Zip Two Sorted Chains

Easy
You get the first nodes of two singly linked lists, left and right; the values in each list are in non-decreasing order. Either list may be empty (that is, None). Join the nodes of both lists into one list that is also in non-decreasing order, and return its first node. You do not need to create new nodes; relinking the existing ones is enough.
Example 1
left=list_node([2, 6, 8]), right=list_node([1, 6, 10, 11]) → [1, 2, 6, 6, 8, 10, 11]

The nodes of both lists line up in ascending order; both 6s stay in the result.

Example 2
left=list_node([]), right=list_node([-4, 0]) → [-4, 0]

The first list is empty, so the answer is the second list as it is.

Example 3
left=list_node([]), right=list_node([]) → None
Constraints
  • Each list has between 0 and 50 nodes
  • -100 ≤ Node.val ≤ 100
  • Both lists are sorted in non-decreasing order
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsCut Out Matching Nodes EasyFlip the Chain EasySymmetric Bead String EasyAdding Digit Lists MediumTrade Places in Twos Medium
loading Python…
Input
left=list_node([2, 6, 8]), right=list_node([1, 6, 10, 11])
Expected
[1, 2, 6, 6, 8, 10, 11]

Run checks the first 3 tests in your browser. Submit checks all 96 tests on the server, hidden ones included.