Subarrays With K Different Integers

easy
1. Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.) 2. Return the number of good subarrays of A. EXAMPLE Input: A = [1,2,1,2,3], K = 2 Output: 7 Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].

Input Format

First line contains two integers N(size) and K. Second line contains N space separated integers.

Output Format

Return the number of good subarrays.

Constraints

1 <= A.length <= 20000
 1 <= A[i] <= A.length
 1 <= K <= A.length

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
5 3
1 2 1 3 4
Output
3
Previous
Merge K Sorted Arrays
Next
Strobogrammatic Number

Related Questions