I am solving MEX as a practice problem but I am not able to pass the second subtask’s second condition, it keeps giving me WA… Please help me with the test case. My code:
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n,k;
cin>>n>>k;
int a[n];
int c[200000]={0};
for(int i=0;i<n;i++)
{
cin>>a[i];
c[a[i]]++;
}
int ans = 0;
for(int i=0;i<200000;i++)
{
if(c[i] == 0 && k >= 0)
{
ans = i;
k--;
}
}
cout<<ans<<endl;
}
return 0;
}