Source Code
// {In the Name of Allah, the Most Beneficent, the Most Merciful }
 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
#define mp make_pair
#define pb push_back
#define pf push_front
#define IOS ios_base::sync_with_stdio(0);cin.tie(NULL);
#define no cout<<"NO\n"
#define yes cout<<"YES\n"
#define el "\n"
 
 map<int,int>frq;

 
int main()
{
    /**/IOS/**/
   int t;
   cin>>t;
   
   while(t--)
   {
  
   	int m=0 , a , n;
   	frq.clear();
   	cin>>n;
   	for(int i=0 ; i<n ; i++)
   	{
   		cin>>a;
   		frq[a]++;
   		m=max(a,m);
	}
	
	if(frq[m]==2)
	cout<<n-1<<el;
	else if (frq[m]==1)
	cout<<n<<el;
	else
	cout<<-1<<el;
	
   }
   
   
}//main















Copy
Proud Competitors aram
GNU G++17
56 ms
1.7 MB
Accepted