Find the greater element

INPUT:
8
4 3 6 1 2 6 4 1

OUTPUT:
6 6 2 6 -1 -1 -1 -1

How do i get output like this:
6 6 -1 2 6 -1 -1 -1

hello @Karanveer
apply ur logic twice because array is circular

here is the code->

I am talking about when the array in not circular
then what changes should i make…
since the output of your code is 6 6 -1 2 6 -1 -1 4 (which is for a circular array)
but the required output is 6 6 -1 2 6 -1 -1 -1 (for a non circular array)

I am talking about when the array in not circular then what changes should i make… since the output of your code is 6 6 -1 2 6 -1 -1 4 (which is for a circular array) but the required output is 6 6 -1 2 6 -1 -1 -1 (for a non circular array)

it is simple na?
iterate from i=n-1 to i=0
and maintian a sorted stack (same as we did in circular stack).

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.