Wrong ans for subtask 2 : not all flavours

i m getting wrong ans for subtask 2. can anyone tell whats wrong with my code?
problem: not all flavor

#include <iostream>
#include<unordered_set>
#include<algorithm>
using namespace std;

int main() {
    int t;
    cin>>t;
    while(t--)
    {
        long long n,k;
        cin>>n>>k;
        long long a[n];
        for(long long i =0;i<n;i++)
        cin>>a[i];
        unordered_set<long long> s;
        long long l=0 ,ml =-1;;
        for(long long i=0;i<n;i++ )
        { 
            s.insert(a[i]);
            l++;
            if(s.size()==k)
            {l=1;
                s.erase(s.begin(),s.end());
                s.insert(a[i]);
            }
            ml= max(l,ml);
        }
        cout<<ml<<endl;
    }
	// your code goes here
	return 0;
}

For the input -
1
4 3
1 2 3 3
The correct output should be - 3 but your code outputs - 2

2 Likes