Is there any optimization that i can apply to my code

#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 ?

Hey @gaganwalia212 this is O(N*N) time complexity, but you can do this problem in O(N) time complexity. It can be done using stack.
I am attaching a editorial so that you can read and get to know how this problem runs (Click here for editorial), also here’s the dry run by me which you can see to get an idea, though if you need you can also ask for that.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.