CodePark/ problems / Merge K Sorted Arrays
START PRACTICINGPRACTICE
Coding problem · Data structures and algorithms › Heaps and top-k

Merge K Sorted Arrays

hardabout 30 minutes in an interview

You get arrays, a list of arrays. Each one is already sorted from smallest to largest. Return one sorted array (smallest to largest) that contains every number from all of them.

  • Keep duplicates. A number that appears 3 times in total appears 3 times in the result.
  • arrays may be empty, and any inner array may be empty.
  • There are up to 1,000 arrays and up to 100,000 numbers in total.
  • Numbers may be negative.
  • Don't change the input arrays.
Input: arrays = [[1, 4, 7], [2, 5], [3, 6, 9]] Output: [1, 2, 3, 4, 5, 6, 7, 9]
Input: arrays = [[], [0, 0], []] Output: [0, 0]
Input: arrays = [] Output: []