Question bankPricingSign in

Merge Two Sorted Linked Lists

Linked ListsMedium1:30

Given two sorted singly linked lists, explain how you would merge them into a single sorted linked list.

For example:

List 1: 1 -> 3 -> 5
List 2: 2 -> 4 -> 6
Merged: 1 -> 2 -> 3 -> 4 -> 5 -> 6

How do you handle cases where the lists have different lengths? What about when one or both lists are empty?

Explain your approach and analyze the time and space complexity.

How to approach it

  • Hint 1

    Compare the heads of both lists and pick the smaller value first.

  • Hint 2

    Consider using a dummy head node to simplify the logic so you don't need special handling for the first element.

  • Hint 3

    After one list is exhausted, append the remainder of the other list directly.

Ready to answer it out loud?

Record your answer in 1:30 and Preptile scores it 1–10 with specifics — what landed, what you skipped, and what to say next time.

Practising needs an invite code. Join the waitlist and we’ll send you one.