Given a matrix mat[][], the task is to count the number of columns that are sorted in descending.
Examples:
Input: mat[][] = {{1, 3}, {0, 2}}
Output: 2
First column: 1 > 0
Second column: 3 > 2
Hence, the count is 2Input: mat[][] = {{2, 2}, {1, 3}}
Output: 1
Approach: Traverse each column one by one and check if the next element ≥ previous element in the same column. If the condition is valid for all the possible elements then increment the count by 1. After all the columns have been traversed, print the count.
Below is the implementation of the above approach:
# Python3 program to count the number of columns # in a matrix that are sorted in descending # Function to count the number of columns # in a matrix that are sorted in descending def countDescCol(A):
countOfCol = 0
for col in zip ( * A):
if all (col[i] > = col[i + 1 ] for i in range ( len (col)  1 )):
countOfCol + = 1
return countOfCol
# Driver code A = [[ 1 , 3 ], [ 0 , 2 ]]
print (countDescCol(A))

2
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a studentfriendly price and become industry ready.
Recommended Posts:
 Sorting rows of matrix in ascending order followed by columns in descending order
 Sorting rows of matrix in descending order followed by columns in ascending order
 Print index of columns sorted by count of zeroes in the Given Matrix
 Ways of filling matrix such that product of all rows and all columns are equal to unity
 Count columns to be deleted to make each row sorted
 Print all elements in sorted order from row and column wise sorted matrix
 heapq in Python to print all elements in sorted order from row and column wise sorted matrix
 Sort Matrix in alternating ascending and descending order rowwise
 Rank of all elements in a Stream in descending order when they arrive
 Count all sorted rows in a matrix
 Maximum sum of any submatrix of a Matrix which is sorted rowwise and columnwise
 Sum of columns of a 2D Matrix where first element is odd
 Interchange elements of first and last columns in matrix
 Remove first X rows and columns from a matrix
 Remove any corner X rows and columns from a matrix
 Number of rows and columns in a Matrix that contain repeated values
 Maximum increase in value of Matrix to keep maximum rows and columns unchanged
 Minimize cost to convert a given matrix to another by flipping columns and reordering rows
 Enlarge a Matrix such that each element occurs in R rows and C columns
 Print numbers in descending order along with their frequencies
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.