Merge K Sorted Arrays
Problem statement
You are given arrays, a collection of integer arrays. Each array is already sorted in nondecreasing order.
Return one array containing every input value in nondecreasing order. Preserve duplicate values. Individual arrays may be empty. If there are no values, return an empty array.
Function
mergeSortedArrays(arrays: int[][]) → int[]Examples
Example 1
arrays = [[1,4],[1,3,5],[],[-2,8]]return = [-2,1,1,3,4,5,8]All seven values are retained; both occurrences of 1 remain.
Example 2
arrays = [[],[]]return = []Neither input array contains a value, so the merged result is empty.
Constraints
0 <= arrays.length <= 1000.- The total number of input values is at most
1000. -10^9 <= arrays[i][j] <= 10^9.- Each input array is sorted in nondecreasing order.