ExamAdda Logo

Merge k Sorted Lists

Easy

You are given an array of k linked lists, where each linked list is sorted in ascending order.

Merge all the linked lists into one sorted linked list and return its head.

Example 1

Input

lists = [[1,4,5],[1,3,4],[2,6]]

Output

[1,1,2,3,4,4,5,6]

Explanation

All three sorted lists are merged into one sorted list.

Example 2

Input

lists = []

Output

[]

Explanation

There are no linked lists to merge, so the result is empty.

Constraints

k == lists.length
0 <= k <= 10^4
0 <= lists[i].length <= 500
-10^4 <= Node.val <= 10^4
The lists are sorted in ascending order.

Hints:

Hint 1

Use a min-heap to keep track of the smallest current element from each list.

Hint 2

Insert the first node of every non-empty list into the heap.

Author & Technical Reviewer

ExamAdda Technical Review Team

Technically reviewed by: ExamAdda Technical Review Team

Technical Reviewers, ExamAdda

Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.

Published

Aug 10, 2026

Last updated

Aug 11, 2026

Content Verification Methodology

Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.

Report a correction:editorial@examadda.org
Auto
Loading editor...
Input

Expected Output