K-Distinct Subarrays
Given an array a of n integers, count how many non-empty contiguous subarrays contain at least k distinct values.
Input
The first line contains two integers n and k.
The second line contains n integers a1,a2,…,an.
Output
Print a single integer: the number of non-empty contiguous subarrays that contain at least k distinct values.
Constraints
- 1≤k≤n≤2⋅105
- −109≤ai≤109
Example 1
5 3
1 2 1 3 2
5
Explanation
The subarrays with at least 3 distinct values are:
- [1,2,1,3]
- [1,2,1,3,2]
- [2,1,3]
- [2,1,3,2]
- [1,3,2]
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.