355. Merge K Sorted Linked Lists

MediumLinked ListHeapMergeLinked List

You are given an array of k linked lists, each sorted in ascending order. Merge all the lists into one sorted linked list and return it. Each list is given as an array of its node values; return the merged list as an array. Input: a JSON array of arrays.

Input: JSON array of sorted arrays.

Output: Array — the merged sorted list.

Examples

Example 1
Input: [[1,4,5],[1,3,4],[2,6]]
Output: [1,1,2,3,4,4,5,6]
Explanation: All three lists merged in order.
Example 2
Input: [[]]
Output: []
Explanation: Empty list.
Example 3
Input: [[1]]
Output: [1]
Explanation: Single list.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →