Substrings with k distinct characters

Write codeMedium25 minMeta style

Your task

Given a string s of lowercase letters and an integer k (1 <= k <= 26, 1 <= len(s) <= 10^4), return the number of (contiguous) substrings that contain EXACTLY k distinct characters.

Examples

count_substrings_with_k_distinct(s: str, k: int) -> int
Example 1
Inputcount_substrings_with_k_distinct("pqpqs", 2)
Output7