I iterate column by column. For each column, I compare characters from top to bottom. If I find any row where the character is smaller than the one above it, the column is not lexicographically sorted, so I count it as a deletion and move to the next column.
class Solution:
def minDeletionSize(self, strs: List[str]) -> int:
rows, cols = len(strs), len(strs[0])
deletions = 0
for c in range(cols):
for r in range(1, rows):
if strs[r][c] < strs[r - 1][c]:
deletions += 1
break
return deletions- Time: O(n × m)
- Space: O(1)
This solution works only because it blindly relies on problem constraints. It makes unchecked assumptions about non-empty input and equal-length strings, offers no defensive handling, and adds nothing beyond the most obvious brute-force approach. The explanation is minimal and lacks any justification beyond restating the code.