So, the problem is basically to count the number of substrings with exactly k distinct characters.There can be duplicate as long as there are k distinct characters.
I was trying sliding window method in which first i check if the element is distinct in the particular window by using a boolean function if the element is distinct then we increament the count and if the count is equal to k then increament answer by 1 and break the loop and restart the sliding window.
Udit Raj Vashisth is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2