Delete Columns to Make Sorted III

You are given an array of n strings strs, all of the same length.

You may choose any deletion indices, and you delete all the characters in those indices for each string.

Suppose you choose a set of deletion indices answer such that after deletions, the final array has every string (row) in lexicographic order. That is, for every row, its remaining characters must be nondecreasing from left to right.

Return the minimum possible value of answer.length.

Example 1
Inputstrs = ["babca","bbazb"]
Output3
After deleting columns 0, 1, and 4, the final array is ["bc", "az"], and both rows are individually in lexicographic order.
Example 2
Inputstrs = ["edcba"]
Output4
If fewer than 4 columns are deleted, the only row will not be lexicographically sorted.

Constraints

  • n == strs.length
  • 1 <= n <= 100
  • 1 <= strs[i].length <= 100
  • strs[i] consists of lowercase English letters.

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate