Merge K Sorted Arrays

easy
1. You are given an matrix with KxK elements. 2. Each row of the matrix is in sorted order. 3. You have to merge the K sorted rows/arrays in the matrix to form a single sorted array. 4. printArrayList is a utility function, feel free to use it for debugging purposes. 5. display is a utility function, feel free to use it for debugging purposes. 6. main takes input from the users and creates the matrix. 7. This is a functional problem. 8. You have to complete the mergeKArrays function. It takes as input a matrix and K. It should return the sorted and merged ArrayList. 9. Don't change the code of main and display.

Input Format

First line takes input K, the size of the square matrix. Next K lines take input K space separated numbers representing the elements of the matrix. Input is handled for you.

Output Format

Merged and sorted ArrayList. Output is handled for you.

Constraints

1 <= K <= 100

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
4
10 20 30 40
15 25 35 45
24 29 37 48
32 33 39 50
Output
10 15 20 24 25 29 30 32 33 35 37 39 40 45 48 50
Previous
Substrings With Concatenation Of All Words
Next
Subarrays With K Different Integers

Related Questions