944. Delete Columns to Make Sorted Easy

@problem@discussion
#Array#String



1/**
2 * [944] Delete Columns to Make Sorted
3 *
4 * You are given an array of n strings strs, all of the same length.
5 * The strings can be arranged such that there is one on each line, making a grid. For example, strs = ["abc", "bce", "cae"] can be arranged as:
6 * 
7 * abc
8 * bce
9 * cae
10 * 
11 * You want to delete the columns that are not sorted lexicographically. In the above example (0-indexed), columns 0 ('a', 'b', 'c') and 2 ('c', 'e', 'e') are sorted while column 1 ('b', 'c', 'a') is not, so you would delete column 1.
12 * Return the number of columns that you will delete.
13 *  
14 * Example 1:
15 * 
16 * Input: strs = ["cba","daf","ghi"]
17 * Output: 1
18 * Explanation: The grid looks as follows:
19 *   cba
20 *   daf
21 *   ghi
22 * Columns 0 and 2 are sorted, but column 1 is not, so you only need to delete 1 column.
23 * 
24 * Example 2:
25 * 
26 * Input: strs = ["a","b"]
27 * Output: 0
28 * Explanation: The grid looks as follows:
29 *   a
30 *   b
31 * Column 0 is the only column and is sorted, so you will not delete any columns.
32 * 
33 * Example 3:
34 * 
35 * Input: strs = ["zyx","wvu","tsr"]
36 * Output: 3
37 * Explanation: The grid looks as follows:
38 *   zyx
39 *   wvu
40 *   tsr
41 * All 3 columns are not sorted, so you will delete all 3.
42 * 
43 *  
44 * Constraints:
45 * 
46 * 	n == strs.length
47 * 	1 <= n <= 100
48 * 	1 <= strs[i].length <= 1000
49 * 	strs[i] consists of lowercase English letters.
50 * 
51 */
52pub struct Solution {}
53
54// problem: https://leetcode.com/problems/delete-columns-to-make-sorted/
55// discuss: https://leetcode.com/problems/delete-columns-to-make-sorted/discuss/?currentPage=1&orderBy=most_votes&query=
56
57// submission codes start here
58
59impl Solution {
60    pub fn min_deletion_size(strs: Vec<String>) -> i32 {
61        0
62    }
63}
64
65// submission codes end
66
67#[cfg(test)]
68mod tests {
69    use super::*;
70
71    #[test]
72    fn test_944() {
73    }
74}
75


Back
© 2025 bowen.ge All Rights Reserved.