Given a string S, find all substring which satisfy following property
Count of all digits appearing in this sub-string must be equal to k.
ex- 110101 and k = 2
Consider sub-string [0-1] "11" should be included in our answer.
[1-4] "1010" also should be included.
[2-5] - "0101" also should be included
All other sub-strings don't satisfy this property.
Constraints
length of string < 10^5
k < 10^5
Variation - what if k is not given and we are supposed to find all substrings in which all digits have equal count, if a digit is present in the sub-string.
I am able to find O(2^10 n10) solution.
My approach -