Merge K Sorted Arrays

Heaps & Top-K, problem 6 of 7

Merge K Sorted Arrays

Medium

LC #23

min-heapk-way merge

Not attempted yet

You're given lists, a list of k lists, each sorted in ascending order. Merge them into one sorted list and return it.

(LeetCode 23 asks the same with linked lists; the heap idea is identical.)

Example 1

Input: lists = [[1,4,5],[1,3,4],[2,6]]
Output: [1,1,2,3,4,4,5,6]

Example 2

Input: lists = []
Output: []

Example 3

Input: lists = [[]]
Output: []

Constraints

  • 0 <= k <= 10^4
  • 0 <= len(lists[i]) <= 500
  • Total number of values N <= 10^5
  • Each lists[i] is sorted ascending

Python

Loading draft…

Test results

8 tests available

No results yet

Run tests your code against the examples; Submit runs the hidden tests too.

3 examples, 5 hidden

Run examples, then submit all tests.