You are given an array of n strings strs, where all strings have the same length. Your task is to delete columns (character positions) to make the strings appear in lexicographic order.
When you delete a column at index i, you remove the character at position i from all strings. For example, if we have strs = ["abcdef", "uvwxyz"] and delete columns {0, 2, 3}, the result is ["bef", "vyz"].
The goal is to find the minimum number of columns to delete so that the remaining strings are in lexicographic order: strs[0] ≤ strs[1] ≤ strs[2] ≤ ... ≤ strs[n-1].
Key insight: Unlike the simpler version of this problem, we need to be smart about which columns to keep. Once we establish that one string is definitively smaller than another at some position, we don't need to worry about those strings in future column checks.
Input & Output
Constraints
- n == strs.length
- 1 ≤ n ≤ 100
- 1 ≤ strs[i].length ≤ 100
- strs[i] consists of lowercase English letters