Here is the code kindly check
I could not find how to get correct output if all elements are same
Still one test case is not getting passed
check now->
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=0;i<n;i++)
{
for(int j=(i+1)%n; (j)!=i ; j= (j+1)%n)
{
if(a[j]>a[i])
{
cout<<a[j]<<" ";
break;
}
else if((j+1)%n == i) // added %
{
cout<<"-1 ";
}
}
}
// removed cout<<"-1 ";
return 0;
}