955. Delete Columns to Make Sorted II Medium

@problem@discussion
#Array#String#Greedy



1/**
2 * [955] Delete Columns to Make Sorted II
3 *
4 * You are given an array of n strings strs, all of the same length.
5 * We may choose any deletion indices, and we delete all the characters in those indices for each string.
6 * For example, if we have strs = ["abcdef","uvwxyz"] and deletion indices {0, 2, 3}, then the final array after deletions is ["bef", "vyz"].
7 * Suppose we chose a set of deletion indices answer such that after deletions, the final array has its elements in lexicographic order (i.e., strs[0] <= strs[1] <= strs[2] <= ... <= strs[n - 1]). Return the minimum possible value of answer.length.
8 *  
9 * Example 1:
10 * 
11 * Input: strs = ["ca","bb","ac"]
12 * Output: 1
13 * Explanation: 
14 * After deleting the first column, strs = ["a", "b", "c"].
15 * Now strs is in lexicographic order (ie. strs[0] <= strs[1] <= strs[2]).
16 * We require at least 1 deletion since initially strs was not in lexicographic order, so the answer is 1.
17 * 
18 * Example 2:
19 * 
20 * Input: strs = ["xc","yb","za"]
21 * Output: 0
22 * Explanation: 
23 * strs is already in lexicographic order, so we do not need to delete anything.
24 * Note that the rows of strs are not necessarily in lexicographic order:
25 * i.e., it is NOT necessarily true that (strs[0][0] <= strs[0][1] <= ...)
26 * 
27 * Example 3:
28 * 
29 * Input: strs = ["zyx","wvu","tsr"]
30 * Output: 3
31 * Explanation: We have to delete every column.
32 * 
33 *  
34 * Constraints:
35 * 
36 * 	n == strs.length
37 * 	1 <= n <= 100
38 * 	1 <= strs[i].length <= 100
39 * 	strs[i] consists of lowercase English letters.
40 * 
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/delete-columns-to-make-sorted-ii/
45// discuss: https://leetcode.com/problems/delete-columns-to-make-sorted-ii/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50    pub fn min_deletion_size(strs: Vec<String>) -> i32 {
51        0
52    }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59    use super::*;
60
61    #[test]
62    fn test_955() {
63    }
64}
65


Back
© 2025 bowen.ge All Rights Reserved.