#include
using namespace std;
int main() {
int n;
cin>>n;
int arr[100000];
for(int i=0;i<n;i++)
cin>>arr[i];
int j;
for(int i=0;i<n;i++)
{
for( j=(i+1)%n;j!=i;j=(j+1)%n)
{
if(arr[j]>arr[i])
{
cout<<arr[j]<<" ";
break;
}
}
if(j==i)
cout<<"-1"<<" ";
}
}
Is there any way I can reduce the time complexity ?
