# Count no. of columns that are not sorted in increasing order

Given an array A of N lowercase letter strings of the same length. The task is to find the count of columns that are not sorted in increasing order.

**Examples:**

Input:A = ["cba", "dah", "ghi"]Output:1 2nd Column ["b", "a", "h"] is not sorted in increasing order.Input:A = ["zyx", "wvu", "tsr"]Output:3 All columns are not sorted in increasing order.

**Approach:** Traverse each column one by one and check if the next element is greater than the previous element in the same column. If not the increment the **countOfCol** by 1 and keep traversing till all the columns get traversed. Print the value of **countOfCol**.

`# function to count the unsorted columns ` `def` `countUnsorted(A): ` ` ` ` ` `countOfCol ` `=` `0` ` ` ` ` `for` `col ` `in` `zip` `(` `*` `A): ` ` ` `if` `any` `(col[i] > col[i ` `+` `1` `] ` `for` `i ` `in` `range` `(` `len` `(col) ` `-` `1` `)): ` ` ` `countOfCol ` `+` `=` `1` ` ` ` ` `return` `countOfCol ` ` ` `# Driver code ` `A ` `=` `[` `"cba"` `, ` `"daf"` `, ` `"ghi"` `] ` `print` `(countUnsorted(A)) ` |

*chevron_right*

*filter_none*

**Output:**

1

## Recommended Posts:

- Sort even and odd placed elements in increasing order
- Python | Get items in sorted order from given dictionary
- Python | Inserting item in sorted list maintaining order
- Sum of columns of a 2-D Matrix where first element is odd
- Python program for Longest Increasing Subsequence
- Python | Check if list is strictly increasing
- Python | Increasing alternate element pattern in list
- Python | Find groups of strictly increasing numbers in a list
- Python | Reverse sequence of strictly increasing integers in a list
- Print a number as string of 'A' and 'B' in lexicographic order
- Python | Finding relative order of elements in list
- Python | Combining two sorted lists
- Python program to insert an element into sorted list
- Python Program for Median of two sorted arrays of same size
- Python Program for Find the closest pair from two sorted arrays

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.