Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Merge Two Sorted Linked Lists
00:00
5 left

Merge Two Sorted Linked Lists

EasyPython

Problem

Given the heads of two singly linked lists list1 and list2, where each list is sorted in non-decreasing order, merge them into a single sorted linked list and return its head. The merged list should be built by reusing the existing nodes, not by creating a separate list of values.

Constraints

  • 0 <= number of nodes in each list <= 50
  • -100 <= Node.val <= 100
  • Both input lists are sorted in non-decreasing order

Function Signature

def merge_two_lists(list1, list2):
Interviewer

Your question is Merge Two Sorted Linked Lists. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.