Merge k Sorted Lists
Given an array of k sorted linked lists, merge all of them into a single sorted linked list and return its head.
Open official problem prompt ↗Produce one globally sorted list from k independently sorted lists as efficiently as possible.
Like a tournament where each list sends its current smallest contender; the heap referees pick the overall smallest each round and that list sends its next contender.
- Input
- lists = [[1,4,5],[1,3,4],[2,6]]
- Output
- [1,1,2,3,4,4,5,6]
- Why
- Merging the three sorted lists produces one sorted sequence 1,1,2,3,4,4,5,6.
k == lists.length0 <= k <= 10^40 <= lists[i].length <= 500-10^4 <= lists[i][j] <= 10^4lists[i] is sorted in ascending orderThe sum of lists[i].length does not exceed 10^4