Source Code
#include <bits/stdc++.h>
using namespace std;
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(0);
    int tt;
    cin >> tt;
    while(tt--)
    {
        int n,mx=0,g=0;
        cin >> n;
        int arr[n];
        for(int i = 0;i<n;cin >> arr[i++]);
        sort(arr,arr+n,greater<int>());
        mx=arr[0];
        for(int i= 1;i<n;i++)
        {
            if(arr[i]==mx)
                g++;
            if(g==2)
            {
                cout << -1 << endl;
                break;
            }
        }
        if(g==1)
        {
            cout << n-1<<endl;
        }
        else if(g==0)
        {
            cout << n << endl;
        }
    }
    return 0;
}
Copy
Proud Competitors Amjeder145
GNU G++17
32 ms
1.1 MB
Accepted