text function mergeKLists(lists): minHeap = empty min-heap (ordered by node value) dummy = new Node(0) curr = dummy // Add all heads to heap for list in lists: if list != null: minHeap.add(list) while not minHeap.isEmpty(): node = minHeap.removeMin() curr.next = node curr = curr.next if node.next != null: minHeap.add(node.next) return dummy.next Time complexity: where = total nodes, = number of lists. Space complexity: for the heap.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/maang-interview-prep/heaps-priority-queues/merge-k-sorted-lists-pseudocode
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░███████████████████████████████████████████████████████████████████████████████████████████████████████