Class Solution
-
- All Implemented Interfaces:
public final class Solution
3458 - Select K Disjoint Special Substrings.
Medium
Given a string
s
of lengthn
and an integerk
, determine whether it is possible to selectk
disjoint special substrings.A special substring is a substring where:
Any character present inside the substring should not appear outside it in the string.
The substring is not the entire string
s
.
Note that all
k
substrings must be disjoint, meaning they cannot overlap.Return
true
if it is possible to selectk
such disjoint special substrings; otherwise, returnfalse
.Example 1:
Input: s = "abcdbaefab", k = 2
Output: true
Explanation:
We can select two disjoint special substrings:
"cd"
and"ef"
."cd"
contains the characters'c'
and'd'
, which do not appear elsewhere ins
."ef"
contains the characters'e'
and'f'
, which do not appear elsewhere ins
.
Example 2:
Input: s = "cdefdc", k = 3
Output: false
Explanation:
There can be at most 2 disjoint special substrings:
"e"
and"f"
. Sincek = 3
, the output isfalse
.Example 3:
Input: s = "abeabe", k = 0
Output: true
Constraints:
<code>2 <= n == s.length <= 5 * 10<sup>4</sup></code>
0 <= k <= 26
s
consists only of lowercase English letters.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final Boolean
maxSubstringLength(String s, Integer k)
-
-
Method Detail
-
maxSubstringLength
final Boolean maxSubstringLength(String s, Integer k)
-
-
-
-