java.lang.Object
g0901_1000.s0955_delete_columns_to_make_sorted_ii.Solution

public class Solution extends Object
955 - Delete Columns to Make Sorted II.<p>Medium</p> <p>You are given an array of <code>n</code> strings <code>strs</code>, all of the same length.</p> <p>We may choose any deletion indices, and we delete all the characters in those indices for each string.</p> <p>For example, if we have <code>strs = [&quot;abcdef&quot;,&quot;uvwxyz&quot;]</code> and deletion indices <code>{0, 2, 3}</code>, then the final array after deletions is <code>[&quot;bef&quot;, &quot;vyz&quot;]</code>.</p> <p>Suppose we chose a set of deletion indices <code>answer</code> such that after deletions, the final array has its elements in <strong>lexicographic</strong> order (i.e., <code>strs[0] <= strs[1] <= strs[2] <= ... <= strs[n - 1]</code>). Return <em>the minimum possible value of</em> <code>answer.length</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> strs = [&ldquo;ca&rdquo;,&ldquo;bb&rdquo;,&ldquo;ac&rdquo;]</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong></p> <p>After deleting the first column, strs = [&ldquo;a&rdquo;, &ldquo;b&rdquo;, &ldquo;c&rdquo;].</p> <p>Now strs is in lexicographic order (ie. strs[0] <= strs[1] <= strs[2]).</p> <p>We require at least 1 deletion since initially strs was not in lexicographic order, so the answer is 1.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> strs = [&ldquo;xc&rdquo;,&ldquo;yb&rdquo;,&ldquo;za&rdquo;]</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong></p> <p>strs is already in lexicographic order, so we do not need to delete anything.</p> <p>Note that the rows of strs are not necessarily in lexicographic order:</p> <p>i.e., it is NOT necessarily true that (strs[0][0] <= strs[0][1] <= &hellip;)</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> strs = [&ldquo;zyx&rdquo;,&ldquo;wvu&rdquo;,&ldquo;tsr&rdquo;]</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong> We have to delete every column.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>n == strs.length</code></li> <li><code>1 <= n <= 100</code></li> <li><code>1 <= strs[i].length <= 100</code></li> <li><code>strs[i]</code> consists of lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • minDeletionSize

      public int minDeletionSize(String[] strs)