Help me in solving CNDY problem

My issue

I am getting desired output in sample run but while submitting getting run time error what modifications should I do plss suggest

My code

#include <iostream>
using namespace std;

int main() {

    int n, T, i, j, k;
    cin >> T;

    for (j = 1; j <= T; j++) {
        cin >> n;
        int arr[2 * n];
        for (i = 0; i < 2 * n; i++) {
            cin >> arr[i];
        }

      
        bool used[100005] = {false};

        
        bool valid = true;
        int count=0;
        for (i = 0; i < 2 * n; i++) {
            if (!used[arr[i]]) {
                used[arr[i]] = true;
            } else {
               
                valid = false;
                count++;
            }
        }

        if (count==1 || count==0) {
            cout << "YES";
        } else {
           cout << "NO";
        }
        cout << endl;
    } 

    return 0;
}

Learning course: 1000 to 1400 difficulty problems
Problem Link: Candies Practice Problem in - CodeChef

@rathbabuli123
refer my c++ code

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        int size = 2 * n;
        int a[size];
        for (int i = 0; i < size; i++)
        {
            cin >> a[i];
        }

        sort(a,a+size);
        string s = "YES";
        
        for (int i = 0; i < size-2; i++)
        {
            if(a[i]==a[i+1] && a[i+1]==a[i+2]){
                s="NO";
            }
        }
        cout<<s<<"\n";
        
    }
    return 0;
}