#3458
Select K Disjoint Special Substrings
medium · 19.1% accepted · 142 likes · top 1%
hash table · string · dynamic programming · greedy · sorting
Description
Given a string s of length n and an integer k, determine whether it is possible to select k 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 select k such disjoint special substrings; otherwise, return false.
Solution