960. Delete Columns to Make Sorted III Hard
1/**
2 * [960] Delete Columns to Make Sorted III
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 every string (row) in lexicographic order. (i.e., (strs[0][0] <= strs[0][1] <= ... <= strs[0][strs[0].length - 1]), and (strs[1][0] <= strs[1][1] <= ... <= strs[1][strs[1].length - 1]), and so on). Return the minimum possible value of answer.length.
8 *
9 * Example 1:
10 *
11 * Input: strs = ["babca","bbazb"]
12 * Output: 3
13 * Explanation: After deleting columns 0, 1, and 4, the final array is strs = ["bc", "az"].
14 * Both these rows are individually in lexicographic order (ie. strs[0][0] <= strs[0][1] and strs[1][0] <= strs[1][1]).
15 * Note that strs[0] > strs[1] - the array strs is not necessarily in lexicographic order.
16 * Example 2:
17 *
18 * Input: strs = ["edcba"]
19 * Output: 4
20 * Explanation: If we delete less than 4 columns, the only row will not be lexicographically sorted.
21 *
22 * Example 3:
23 *
24 * Input: strs = ["ghi","def","abc"]
25 * Output: 0
26 * Explanation: All rows are already lexicographically sorted.
27 *
28 *
29 * Constraints:
30 *
31 * n == strs.length
32 * 1 <= n <= 100
33 * 1 <= strs[i].length <= 100
34 * strs[i] consists of lowercase English letters.
35 *
36 *
37 *
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/delete-columns-to-make-sorted-iii/
42// discuss: https://leetcode.com/problems/delete-columns-to-make-sorted-iii/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47 pub fn min_deletion_size(strs: Vec<String>) -> i32 {
48 0
49 }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56 use super::*;
57
58 #[test]
59 fn test_960() {
60 }
61}
62
Back
© 2025 bowen.ge All Rights Reserved.