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.
Input: lists = [[1,4,5],[1,3,4],[2,6]]
Output: [1,1,2,3,4,4,5,6]
Explanation: The linked-lists are:[ 1->4->5, 1->3->4, 2->6]
merging them into one sorted linked list:
1->1->2->3->4->4->5->6
Input: lists = []
Output: []
Input: lists = [[]]
Output: []
The simplest strategy is to flatten the k linked lists into a single list, sort it, and then reconstruct the linked list from this sorted data. This approach is easy to implement but not efficient.
Utilize a min-heap to efficiently retrieve the smallest current head from k lists and build the final output list. PriorityQueue in Java can manage this as a min-heap by default.
Use the divide-and-conquer technique. Merge lists in pairs and repeat the process until one list remains.