Count number of substrings with exactly k distinct characters

[Question]: You are given a string ‘str’ of lowercase alphabets and an integer’k’ .Your task is to return the count all the possible substrings that have exactly ‘k’ distinct characters.For example:‘str’ = abcad and ‘k’ = 2.We can see that the substrings {ab, bc, ca, ad} are the only substrings with 2 distinct characters. Therefore,

Count number of substrings with exactly k distinct characters Read More »