Explanation
Merge k Sorted Lists is a Hard interview problem tagged [Linked List, Heap]. The winning approach is typically **Heap**.
#23
You are given an array of k linked-lists lists, each linked-list is sorted in ascending order.
Merge all the linked-lists into one sorted linked-list and return it.
Example 1
Input: lists = [[1,4,5],[1,3,4],[2,6]]
Output: [1,1,2,3,4,4,5,6]
Merging the three sorted lists yields one sorted list.
Example 2
Input: lists = []
Output: []
Nothing to merge.
Example 3
Input: lists = [[]]
Output: []
One empty list.
Merge k Sorted Lists is a Hard interview problem tagged [Linked List, Heap]. The winning approach is typically **Heap**.
O(log k) updates beat full sorts when you only need extremes.
Use a priority queue for Top-K, scheduling, or Dijkstra-style extraction of minima.
Pattern-level skeleton only — not this problem’s exact answer. Adapt it to the statement.
Time: O(n log n)
Space: O(n)
Before coding, restate the problem, name the pattern (Heap), and write the invariant or DP state in one sentence.
Got it?
Mark #23 Merge k Sorted Lists as understood when the pattern clicks.