📚 PracticeHardAlgorithm ProblemCoding Ready

Merge K Sorted Lists

linked-listheapdivide-and-conquer
LeetCode #23
Updated Dec 20, 2025

Question

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

LeetCode: Merge K Sorted Lists

Merge all the linked-lists into one sorted linked-list and return it.

Example:

Input: lists = [[1,4,5],[1,3,4],[2,6]]
Output: [1,1,2,3,4,4,5,6]

Explanation:
The linked-lists are:
[
  1->4->5,
  1->3->4,
  2->6
]
Merging them into one sorted list:
1->1->2->3->4->4->5->6

Hints

Hint 1

You know how to merge 2 sorted lists. Can you use a similar approach but track k list heads?

Hint 2

Use a min heap to always get the smallest node among k list heads. What do you store in the heap?

Hint 3

When you add a node to the heap, include an index to avoid comparing ListNode objects directly (they're not comparable).


Your Solution

python
Auto-saves every 30s

Try solving the problem first before viewing the solution


0:00time spent