ASAPUtils Logo ASAPUtils
Week 5

Merge K Sorted Lists

Merge K Sorted Lists with a size-k min-heap frontier, including the one-node- per-list invariant, C++ and JavaScript heap implementations, complexity, divide-and-conquer alternative, and an interactive multi-list trace.

hard Linked Lists O(N log k) time · O(k) space Open on LeetCode ↗

The problem

Merge k individually sorted linked lists into one sorted linked list and return its head.

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

Related Problems