Dominant Piranha Codeforces Solution

Dominant Piranha Codeforces Solution

In this post, the Dominant Piranha Codeforces Solution is given. Question details : Codeforces Round #677 (Div. 3), problem: (C) Dominant Piranha.

Dominant Piranha Codeforces Solution

#include<bits/stdc++.h>
using namespace std;
const int MOD=1000000007;
#define ll long long
#define Fastio ios_base::sync_with_stdio(false); 
cin.tie(NULL);
#define pb push_back
int main()
{
Fastio;
ll t; 
cin>>t;
while(t--) 
{
ll n,x,flag=0, flag2=0,m=INT_MIN; 
cin>>n; 
ll a[n]; 
for(ll i=0;i<n;i++)
cin>>a[i]; 
x=a[0];
for(ll i=1;i<n;i++)
{
if(a[i]==x)
continue;
else
{
flag=1;
break;
}
}
if(flag==0)
cout<<-1<<endl;
else
{
for(ll i=0;i<n;i++)
m=max(m,a[i]);
for(ll i=1;i<n-1;i++)
{
if(a[i]==m && (a[i+1]<a[i] || a[i-1]<a[i]))
{
cout<<i+1<<endl;
flag2=1;
break;
}
}
if(flag2==0)
{
if(a[0]==m && a[0]>a[1])
{
cout<<1<<endl;
flag2=1;
}
if(a[n-1]>a[n-2] && flag2==0)
cout<<n<<endl;
}
}
}
}


The solution of the above program is contributed by Vishal Vaibhab (IIT BHU). If you like TheCode11, then do follow us on Facebook, Twitter and Instagram.

Previous Post Next Post

Contact Form