Merge k sorted linked lists.
HardUnlock detailed company stats for this questionUpgrade
Merge K Sorted Linked Lists. You are given an array of k linked-lists lists, each linked-list is sorted in ascending order. Your task is to merge all the linked-lists into one sorted linked-list and return it.
Examples:
- If
lists = [[1,4,5],[1,3,4],[2,6]], where each array represents a linked-list, the merged and sorted linked-list would be[1,1,2,3,4,4,5,6]. The output for the merged list should be in array form for simplicity. - If
lists = [], indicating an array of no linked-lists, the output should be[]. - If
lists = [[]], representing an array with a single empty linked-list, the output should be[]. - If
lists = [[],[1]], where the first linked-list is empty and the second contains a single element, the output should be[1]. - If
lists = [[-1,5,11],[],[6,10]], the merged and sorted linked-list should be[-1,5,6,10,11].
Constraints:
k == lists.length0 <= k <= 10^40 <= lists[i].length <= 50010^4 <= lists[i][j] <= 10^4lists[i]is sorted in an increasing order.
In this video, Simon, Spotify Software Engineer, answers an interview question about merging k sorted linked lists.
Interview experiences
4 sharedRelated questions
Merge two sorted linked listMerge two sorted listsSort a doubly linked list using merge sort.Related courses

Course

Course










