Given an n x n matrix, where every row and column is sorted in non-decreasing order. Print all elements of matrix in sorted order.
Input : mat= [[10, 20, 30, 40], [15, 25, 35, 45], [27, 29, 37, 48], [32, 33, 39, 50]] Output : Elements of matrix in sorted order [10, 15, 20, 25, 27, 29, 30, 32, 33, 35, 37, 39, 40, 45, 48, 50]
Elements of matrix in sorted order [10, 15, 20, 25, 27, 29, 30, 32, 33, 35, 37, 39, 40, 45, 48, 50]
This article is contributed by Shashank Mishra (Gullu). If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Print all elements in sorted order from row and column wise sorted matrix
- Count Negative Numbers in a Column-Wise and Row-Wise Sorted Matrix
- Count zeros in a row wise and column wise sorted matrix
- Largest row-wise and column-wise sorted sub-matrix
- Search in a row wise and column wise sorted matrix
- Leftmost Column with atleast one 1 in a row-wise sorted binary matrix
- Leftmost Column with atleast one 1 in a row-wise sorted binary matrix | Set 2
- Check if a grid can become row-wise and column-wise sorted after adjacent swaps
- Kth smallest element in a row-wise and column-wise sorted 2D array | Set 1
- Merge two sorted arrays in Python using heapq
- Python | Relative sorted order in Matrix
- Find median in row wise sorted matrix
- Find a common element in all rows of a given row-wise sorted matrix
- Search in a sorted 2D matrix (Stored in row major order)
- Program to print elements of a Matrix row-wise skipping alternate elements