Count contiguous stretches with exactly k distinct symbols
You have the sequence of symbols traded on a venue, one per tick. Count how many contiguous windows contain exactly k distinct symbols.
symbols = ["A", "B", "A", "C"], k = 2
-> 4 # A B, A B A, B A, A C
Return the count. Aim for .
Show a hint
"Exactly k" is hard to sweep directly. Can you express it as a difference of two "at most" counts?
Your answer
This one is open-ended. Work it through, then check your reasoning against the full solution.