3458. Select K Disjoint Special Substrings Medium

@problem@discussion
#Hash Table#String#Dynamic Programming#Greedy#Sorting



1/**
2 * [3458] Select K Disjoint Special Substrings
3 *
4 * Given a string s of length n and an integer k, determine whether it is possible to select k disjoint special substrings.
5 * A special substring is a <span data-keyword="substring-nonempty">substring</span> where:
6 * 
7 * 	Any character present inside the substring should not appear outside it in the string.
8 * 	The substring is not the entire string s.
9 * 
10 * Note that all k substrings must be disjoint, meaning they cannot overlap.
11 * Return true if it is possible to select k such disjoint special substrings; otherwise, return false.
12 *  
13 * <strong class="example">Example 1:
14 * <div class="example-block">
15 * Input: <span class="example-io">s = "abcdbaefab", k = 2</span>
16 * Output: <span class="example-io">true</span>
17 * Explanation:
18 * 
19 * 	We can select two disjoint special substrings: "cd" and "ef".
20 * 	"cd" contains the characters 'c' and 'd', which do not appear elsewhere in s.
21 * 	"ef" contains the characters 'e' and 'f', which do not appear elsewhere in s.
22 * </div>
23 * <strong class="example">Example 2:
24 * <div class="example-block">
25 * Input: <span class="example-io">s = "cdefdc", k = 3</span>
26 * Output: <span class="example-io">false</span>
27 * Explanation:
28 * There can be at most 2 disjoint special substrings: "e" and "f". Since k = 3, the output is false.
29 * </div>
30 * <strong class="example">Example 3:
31 * <div class="example-block">
32 * Input: <span class="example-io">s = "abeabe", k = 0</span>
33 * Output: <span class="example-io">true</span>
34 * </div>
35 *  
36 * Constraints:
37 * 
38 * 	2 <= n == s.length <= 5 * 10^4
39 * 	0 <= k <= 26
40 * 	s consists only of lowercase English letters.
41 * 
42 */
43pub struct Solution {}
44
45// problem: https://leetcode.com/problems/select-k-disjoint-special-substrings/
46// discuss: https://leetcode.com/problems/select-k-disjoint-special-substrings/discuss/?currentPage=1&orderBy=most_votes&query=
47
48// submission codes start here
49
50impl Solution {
51    pub fn max_substring_length(s: String, k: i32) -> bool {
52        false
53    }
54}
55
56// submission codes end
57
58#[cfg(test)]
59mod tests {
60    use super::*;
61
62    #[test]
63    fn test_3458() {
64    }
65}
66

Back
© 2026 bowen.ge All Rights Reserved.