Module 3 · Linked List · Linked List Questions

Merge k sorted lists

Each list's smallest waiting node sits in a priority queue. Poll the smallest, link it after the dummy sortedHead's chain, and put the next node of its list in its place — until the queue is empty.

Above are the input lists; the merged list grows behind the dummy sortedHead. The queue is a PriorityQueue ordered by val: poll() takes the front.