Wrong answer (NOTALLFL)

problem link https://www.codechef.com/LTIME81B/problems/NOTALLFL/
feb lunctime_div 2_problem 2
#include <bits/stdc++.h>
using namespace std;

int main() {
int t;
cin>>t;
while(t–)
{
unordered_map<int, int> map;
int n,k;
cin>>n>>k;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
int index=0,count=0,max1=0;
if(k>1)
for(int i=0;i<n;)
{
map[a[i]]++;
if(map.size()!=k)
{
count++;
i++;
}
else
{
// cout<<map.size()<<" “<<i;
max1=max(max1,count);
map.clear();
count=0;
}
}
max1=max(max1,count);
cout<<max1<<”\n";
}
return 0;
}

Can any one tell me the problem with this solution

For this test u are getting WA
10 4
1 2 3 4 4 4 4 2 2 1
ans should be 8

But i also didnt solved this question fully…if someone can pls tell whats wrong in my code will help a lot
my code link- https://www.codechef.com/viewsolution/29987013

4444221 should bhe answer and the length is 7 so i think the final answer should bhe 7

2 3 4 4 4 4 2 2 is the longest

Ohh thaks a lot