New update is available. Click here to update.

Last Updated: 22 Sep, 2020

Difficulty: Moderate

```
If the matrix is:
10 20 30 40
15 20 35 42
27 29 37 46
32 33 38 49
The output will be the elements of matrix in sorted order:
10 15 20 20 27 29 30 32 33 35 37 38 40 42 46 49
```

```
Can you solve this in O((N ^ 2) * log(N)) time and O(N) space complexity?
```

```
The first line of input contains a single integer T, representing the number of test cases or queries to be run.
Then the T test cases follow.
The first line of each test case contains a positive integer N, which represents the number of rows and columns in the matrix.
The next 'N' lines, each contains 'N' single space-separated positive integers representing the elements in a row of the matrix.
```

```
For each test case, print a single line containing the elements of the matrix in sorted order.
```

```
You do not need to print anything. It has already been taken care of. Just implement the given function.
```

```
1 <= T <= 10
1 <= N <= 100
1 <= MAT[i][j] <= 10^5
Time Limit: 1 sec
```

SIMILAR PROBLEMS

Max Prefix

Posted: 31 Oct, 2022

Difficulty: Easy

Merge Two Sorted Arrays Without Extra Space

Posted: 19 Nov, 2022

Difficulty: Moderate

Search In A Sorted 2D Matrix

Posted: 23 Nov, 2022

Difficulty: Moderate

Spiral Matrix

Posted: 24 Nov, 2022

Difficulty: Easy

Sort 0s, 1s, 2s

Posted: 24 Dec, 2022

Difficulty: Easy

Popular Interview Problems: