Help me in solving MISSP problem

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

@b_suvonov
logic is quite simple .
Just calculate the xor of the whole array.

Yes, i saw that solution as well, but my algorithm should work too, right? I want to make this code work first, do you know where the issue is?

@b_suvonov
what if i have multiple pair of the same doll
like for test case
5
1 1 1 1 2
for this test case your code will fail.