Substring With At Least K Distinct Characters
Input: S = "abcabcabca", k = 4
Output: 0
Explanation: There are only three distinct characters in the string.Input: S = "abcabcabcabc", k = 3
Output: 55
Explanation: Any substring whose length is not smaller than 3 contains a, b, c.
For example, there are 10 substrings whose length are 3, "abc", "bca", "cab" ... "abc"
There are 9 substrings whose length are 4, "abca", "bcab", "cabc" ... "cabc"
...
There is 1 substring whose length is 12, "abcabcabcabc"
So the answer is 1 + 2 + ... + 10 = 55. 10 ≤ length(S) ≤ 1,000,000
1 ≤ k ≤ 26Basic Idea:
Java Code:
Previous1498. Number of Subsequences That Satisfy the Given Sum ConditionNextMinimum Window Substring
Last updated