My issue
I can’t find the issue in my code, please help!
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while(T--){
int N;
cin >> N;
int pairComplete = 1;
int type = -1;
int types[N]={0};
for(int i=0; i<N; i++){
cin >> types[i];
}
sort(types, types+N);
for(int i=0; i<N; i++){
if(types[i]!=type && pairComplete){
type = types[i];
pairComplete=0;
}
else if(types[i]==type && !pairComplete){
pairComplete=1;
}
else{
cout << type << endl;
pairComplete=1;
break;
}
}
if(!pairComplete){
cout << types[N-1] << endl;
}
}
}
Learning course: Arrays, Strings & Sorting
Problem Link: Chef and Dolls Practice Problem in - CodeChef