My issue
I have written this code. I think my calculation & logic is right, but it's not calculating proper. Please, help me someone to find, what is the problem in this.
My code
#include <iostream>
using namespace std;
int main() {
int t; cin>>t;
while(t--)
{
int N; cin>>N;
int A[2*N];
for(int i=0; i<2*N; i++)
{
cin>>A[i];
}
int flag = 0;
for(int k=0; k<(2*N)-1; k++)
{
for(int i=k; i<2*N; i++)
{
if(A[k] == A[i]){
flag ++;
if(flag > 2) break;
}
}
if(flag > 2)
{
cout << "No" <<endl;
break;
}
}
if(flag < 3)
{
cout << "Yes"<< endl;
}
}
return 0;
}
Problem Link: CNDY Problem - CodeChef