You are given arrays, a list of integer arrays where each array is individually sorted in non-decreasing order (some arrays may be empty), and an integer k.
Return the k smallest elements among all elements of all arrays, in non-decreasing order. Duplicate values count separately; each occurrence is its own element.
Examples
Example 1
Input: arrays = [[1,4,7],[2,5,8],[3,6,9]], k = 5
Output: [1,2,3,4,5]
Explanation: The five smallest elements across all three arrays are 1, 2, 3, 4, and 5.
Example 2
Input: arrays = [[],[1,3],[2]], k = 2
Output: [1,2]
Explanation: Empty arrays contribute nothing; the two smallest elements overall are 1 and 2.
Example 3
Input: arrays = [[1,1],[1,2]], k = 3
Output: [1,1,1]
Explanation: The value 1 occurs three times in total, and each occurrence counts.
Constraints
1≤arrays.length≤100
0≤arrays[i].length≤104
1≤N≤105, where N is the total number of elements across all arrays
−109≤arrays[i][j]≤109
Each arrays[i] is sorted in non-decreasing order.
1≤k≤N
Loading editor...
Log in to run your code. Your draft is saved in this browser.Log inSign up