Solved Problem - Merge K Sorted Arrays
We'll cover the following
Problem statement
Given sorted arrays of length . Print the sorted set of integers after merging the arrays.
Input format
The first line of input consists of two space-separated integers and .
The next lines consist of integers each, representing the arrays.
Output format
Print a single line of integers - the sorted merged array.
Sample
Input
3 4
1 3 5 7
3 7 9 11
2 4 6 8
Output
1 2 3 3 4 5 6 7 7 8 9 11
Explanation
The merged array is -
The sorted array is -
Brute force
The naive approach would be to create a merged array of size and sort using any of the faster-sorting algorithms, the time complexity will be
Get hands-on with 1400+ tech skills courses.