205. Merge K Sorted Arrays
You are given k sorted arrays, each of size k. Merge all the arrays into one sorted array and return it.
You should use an efficient algorithm with O(k² log k) time complexity.
Example 1:
Input: k = 3, arr = [[1,2,3],[4,5,6],[7,8,9]]
Output: [1, 2, 3, 4, 5, 6, 7, 8, 9]
Example 2:
Input: k = 4, arr = [[1,2,3,4],[2,2,3,4],[5,5,6,6],[7,8,9,9]]
Output: [1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 8, 9, 9]
Now Your Turn!
Pick the correct output for the given inputInput: k = 1, arr = [[10]]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= k <= 100
- Each row arr[i] is sorted in ascending order
- Total elements = k × k (i.e., the matrix is k x k)