java.lang.Object
g0901_1000.s0960_delete_columns_to_make_sorted_iii.Solution

public class Solution extends Object
960 - Delete Columns to Make Sorted III.<p>Hard</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 <strong>every string (row) in lexicographic</strong> order. (i.e., <code>(strs[0][0] <= strs[0][1] <= ... <= strs[0][strs[0].length - 1])</code>, and <code>(strs[1][0] <= strs[1][1] <= ... <= strs[1][strs[1].length - 1])</code>, and so on). 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;babca&rdquo;,&ldquo;bbazb&rdquo;]</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong> After deleting columns 0, 1, and 4, the final array is strs = [&ldquo;bc&rdquo;, &ldquo;az&rdquo;]. Both these rows are individually in lexicographic order (ie. strs[0][0] <= strs[0][1] and strs[1][0] <= strs[1][1]). Note that strs[0] > strs[1] - the array strs is not necessarily in lexicographic order.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> strs = [&ldquo;edcba&rdquo;]</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> If we delete less than 4 columns, the only row will not be lexicographically sorted.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> strs = [&ldquo;ghi&rdquo;,&ldquo;def&rdquo;,&ldquo;abc&rdquo;]</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> All rows are already lexicographically sorted.</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)