Dodomeki
Sign in

162. Merging Sorted Lists

Hard

An analytics team maintains several lists of integers, each already sorted in nondecreasing order. To prepare a report, combine all the values into one sorted list.

The parameter listas contains the input lists. Preserve every occurrence, including duplicates, and return a list containing all numbers in nondecreasing order. If listas contains no values, return an empty list.

Example 1
Input: listas = [[1, 4, 8], [2, 3, 9]]
Output: [1, 2, 3, 4, 8, 9]
Explanation: The values from both lists are combined in order.
Example 2
Input: listas = [[], [-5, -5, 0], [-2, 3]]
Output: [-5, -5, -2, 0, 3]
Explanation: The empty lists do not affect the result, and duplicate occurrences are preserved.
Example 3
Input: listas = [[], []]
Output: []
Constraints
  • 0 <= listas.length <= 10^4
  • 0 <= listas[i].length
  • The sum of the lengths of all lists is at most 10^5.
  • -10^9 <= listas[i][j] <= 10^9
  • Each list is sorted in nondecreasing order.
HeapSorting
Caso 1
listas =
[[1,4,8],[2,3,9]]
Expected =
[1,2,3,4,8,9]
Caso 2
listas =
[[],[-5,-5,0],[-2,3]]
Expected =
[-5,-5,-2,0,3]
Caso 3
listas =
[[],[]]
Expected =
[]

Run checks these 3 cases. Submit runs all 12, including hidden ones.