Merge M Sorted Arrays
MediumPython 3ArraysHeapsSorting
You are given a collection of arrays, each of which is already sorted in non-decreasing order. Merge them into a single array sorted in non-decreasing order and return it.
Constraints: - There may be any number of input arrays, including zero. - Individual arrays may be empty and may have different lengths. - Values are integers and may be negative or duplicated.
Examples: [[1, 4, 7], [2, 5], [3, 6]] -> [1, 2, 3, 4, 5, 6, 7] [[1, 1, 45], [1, 4, 23]] -> [1, 1, 1, 4, 23, 45] [[], [2], []] -> [2] [] -> []
Python 3, run in your browser. Run tests runs the problem's own tests with a free account; the AI interviewer reads your code and your runs in a practice interview.
Loading the editor…