Exactly K Distinct
Count the contiguous subarrays containing EXACTLY K distinct values.
Input: the first line has N and K; the second line has N integers.
Output: the number of subarrays with exactly K distinct values.
Constraints:
- 1 ≤ N ≤ 105
- 1 ≤ K ≤ N
- 1 ≤ ai ≤ 109
Sample Tests
Input 1
4 2 1 2 1 3
Output 1
4
Input 2
3 1 5 5 5
Output 2
6
Discussion (opens after you solve — no spoilers before)
No comments yet.