404. Merge M Sorted Lists of Variable Size

HardLinked ListHeapMergeLinked List

Given m sorted linked lists of varying lengths (some possibly empty), merge them into one sorted list. Each list is given as a sorted array; 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],[2],[3,5,6]]
Output: [1,2,3,4,5,6]
Explanation: Variable-size lists merged.
Example 2
Input: [[]]
Output: []
Explanation: Single empty list.
Example 3
Input: [[1]]
Output: [1]
Explanation: Single list.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →