~/algor $ cat problems/ikki-korsatkich-k-xil-son
Segment with at most k distinct numbers
Medium
1000 ms
128 MB
58%
An array $a$ of $n$ positive integers and a positive integer $k$ are given. Find the length of the longest segment of consecutive elements of the array in which at most $k$ distinct numbers occur.
Input
The first line contains two positive integers: $n$ and $k$. The second line contains $n$ positive integers $a_{i}$ separated by spaces.
Output
One integer — the length of the longest segment.
Note
$1 \le k \le n \le 2 * 10^{5}$
$1 \le a_{i} \le 10^{9}$
Examples
Input #1
8 2 1 2 1 3 3 4 3 3
Output #1
5
Input #2
3 3 5 6 7
Output #2
3