Sorting a matrix | Sorting all elements of a given matrix in ascending order

Sorting a matrix | Sorting all elements of a given matrix in ascending order

In this article, we will discuss on sorting a matrix. Let us assume a n x n matrix. We need to sort this given matrix in a strict order. Here strict order means that matrix is sorted in a way such that all elements in a row are sorted in ascending order and for row i, where 1 <=i<= n-1, first element of row ‘i’ is greater than or equal to the last element of row ‘i-1’.



Sorting a matrix | Sorting all elements of a given matrix in ascending order


Test case:nnInput:n3 3nn9 7 5n2 8 6n10 3 1nnOutput:n1 2 3n5 6 7n8 9 10nn


Program for sorting a matrix

@@coding::1@@




Sorting a matrix | Sorting all elements of a given matrix in ascending order




Sorting a matrix | Sorting all elements of a given matrix in ascending order


c