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.
30:00
Java
Merge K Sorted Lists
hard
Topics
Companies
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: [[1,4,5],[1,3,4],[2,6]]
Output: [1,1,2,3,4,4,5,6]
Constraints:
k==lists.length
0≤k≤104
0≤lists[i].length≤500
−104≤lists[i][j]≤104
lists[i] is sorted in ascending order.
The sum of lists[i].length will not exceed 104.
Input
arr =[[1,4,5],[1,3,4],[2,6]]
Init lists and heap
List 1
1
4
5
List 2
1
3
4
List 3
2
6
Min Heap (Values)
1
1
2
Result
Null
Variables
No variables to display
DepthFunction Call
Stack empty
0/25
Asked in these interview guides
Company guides that list this problem among their sample questions.