Skip to main content
All Questions

Merge two sorted linked list

Easy
Unlock detailed company stats for this questionUpgrade

You're given the heads of two sorted linked lists, list1 and list2. Merge them into one sorted list by splicing their nodes together, and return the head of the merged list.

Example 1

Input: list1 = [1, 2, 4], list2 = [1, 3, 4] Output: [1, 1, 2, 3, 4, 4]

Example 2

Input: list1 = [], list2 = [0] Output: [0]

An empty list contributes nothing.

Constraints

  • Each list has between 0 and 50 nodes.
  • -100 <= Node.val <= 100
  • Both lists are sorted in non-decreasing order.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.