https://www.codechef.com/problems/NOTALLFL

ABOVE IS QUESTION LINK AND WHERE IS my logic wrong please provide me test cases
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t,k,n;
cin>>t;
while(t–)
{
cin>>n>>k;
int a[n],b[n+1]={0};
for(int i=0;i<n;i++)
{
cin>>a[i];
}
vectorv;int checkkarwalo=0;
for(int i=0;i<n;i++)
{
if(b[a[i]]==0)
{
checkkarwalo++;
b[a[i]]=1;
}
if(checkkarwalo<k)
{
v.push_back(a[i]);
}
else if(checkkarwalo==k)
break;

    }
    cout<<v.size()<<'\n';
    
}

}

Hey @amitmodi123 forum software makes difficult to read any code. So i suggest you to first check out this :point_right: [Tutorial] CoLoR format the Code!

2 Likes