Lexicographic Rows
Practice
2.2 (6 votes)
Algorithms
Basic programming
Basics of implementation
Implementation
Medium
Problem
87% Success 4913 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given a \(N \times M\) matrix of characters. In one operation you can remove a column of the matrix. You can perform as many operations as you want. Your task is to make the final matrix interesting i.e. the string formed by the characters of \(i^{th}\) row is lexicographically smaller or equal to the string formed by the characters of the \((i+1)^{th}\) row. You need to use minimum number of operations possible.
An empty matrix is always a interesting matrix.

Input
The first line contains two integers \(N\)and  \(M\).
The next \(N\) lines contain \(M\) letters each.

Output
In the output, you need to print the minimum number of operations to make the matrix interesting.

Constraints
\(1 \le N, M \le 100 \)

There are only lowercase English alphabets as characters in the input.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
5 votes
Tags:
Basic Programming
Points:30
16 votes
Tags:
Basic ProgrammingBasics of ImplementationHash MapsImplementationMedium
Points:30
207 votes
Tags:
ApprovedMathMediumReady