Don’t worry, unlock all articles / blogs on PrepInsta by just simply logging in on our website
Print Elements in Sorted Order using Row-Column wise Sorted Matrix in Python
April 30, 2022
Print Elements in Sorted Order using Row-Column wise Sorted Matrix in Python
Here, on this page, we will discuss the program to Print Elements in Sorted Order using Row-Column wise Sorted Matrix in Python programming language. We are given a matrix in which each row and column are sorted in a non-decreasing manner.
Algorithm
Let’s say the number of rows is n and the number of columns is m.
Now, create an array of sizes (n*m).
Insert all the elements of the matrix in the declared array.
Matrix = [[1, 20, 43, 14],
[50, 69, 17, 81],
[99, 10, 11, 22],
[13, 54, 95, 16]]
arr = []
x, n, m = 0, 4, 4
for i in range(n):
for j in range(m):
arr.append(Matrix[i][j])
size = n*m
arr.sort()
for i in range(size):
print(arr[i], end=" ")
Login/Signup to comment