
The length of all the strings in the array is the same.
If the given array is [ “bde”, “dcf”, “gat” ], then it can be assumed to arranged as
bde
dcf
gat
Now the ‘0-th’ column (‘b’, ‘d’, ‘e’) and ‘2-th’ column ( ‘e’, ‘f’, ‘t’ ) are lexicographically sorted but the ‘1-st’ column ( ‘d’, ‘c’, ‘a’ ) is not sorted lexicographically. So you need to return 1.
The first line contains a single integer ‘T’, denoting the number of test cases.
Each test case’s first line contains ‘N’, denoting the number of strings in the array.
The next ‘N’ lines contain strings of the same length that make up ‘Strings’.
For each test case, print a single line containing a single integer denoting the number of columns that are not sorted lexicographically.
The output of each test case will be printed in a separated line.
You don’t need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 50
1 <= N <= 100
1 <= L <= 10 ^ 3
Where ‘T’ is the number of test cases, ‘n’ is the number of strings, and ‘L’ is each string’s length.
Time limit: 1 sec.
The simple idea is to traverse through every column of strings. For each column, check if it is lexicographically sorted or not. If not, increment the count by one.
Algorithm