mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-05 07:21:40 +08:00
59 lines
2.4 KiB
HTML
59 lines
2.4 KiB
HTML
<p>Given a string <code>s</code> of length <code>n</code> and an integer <code>k</code>, determine whether it is possible to select <code>k</code> disjoint <strong>special substrings</strong>.</p>
|
|
|
|
<p>A <strong>special substring</strong> is a <span data-keyword="substring-nonempty">substring</span> where:</p>
|
|
|
|
<ul>
|
|
<li>Any character present inside the substring should not appear outside it in the string.</li>
|
|
<li>The substring is not the entire string <code>s</code>.</li>
|
|
</ul>
|
|
|
|
<p><strong>Note</strong> that all <code>k</code> substrings must be disjoint, meaning they cannot overlap.</p>
|
|
|
|
<p>Return <code>true</code> if it is possible to select <code>k</code> such disjoint special substrings; otherwise, return <code>false</code>.</p>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">s = "abcdbaefab", k = 2</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">true</span></p>
|
|
|
|
<p><strong>Explanation:</strong></p>
|
|
|
|
<ul>
|
|
<li>We can select two disjoint special substrings: <code>"cd"</code> and <code>"ef"</code>.</li>
|
|
<li><code>"cd"</code> contains the characters <code>'c'</code> and <code>'d'</code>, which do not appear elsewhere in <code>s</code>.</li>
|
|
<li><code>"ef"</code> contains the characters <code>'e'</code> and <code>'f'</code>, which do not appear elsewhere in <code>s</code>.</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">s = "cdefdc", k = 3</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">false</span></p>
|
|
|
|
<p><strong>Explanation:</strong></p>
|
|
|
|
<p>There can be at most 2 disjoint special substrings: <code>"e"</code> and <code>"f"</code>. Since <code>k = 3</code>, the output is <code>false</code>.</p>
|
|
</div>
|
|
|
|
<p><strong class="example">Example 3:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">s = "abeabe", k = 0</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">true</span></p>
|
|
</div>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>2 <= n == s.length <= 5 * 10<sup>4</sup></code></li>
|
|
<li><code>0 <= k <= 26</code></li>
|
|
<li><code>s</code> consists only of lowercase English letters.</li>
|
|
</ul>
|