Query with the stack code

I have a query like for :

Input: 1 2 2 3
Output will be: 2 2 3 -1 or 2 3 3 -1 or 2 3 -1 -1

Please explain this?

@dhruvtrehan45 answer should be 2 3 3 -1
since 2 is greater than 1, 3 is greater than both 2’s and we don’t have any element greater than 3 so -1 for that.

https://ide.codingblocks.com/s/317143 What is the error in my code then?

it is said in the problem statement that array is circular so if you can’t find greater element in the right side of an element then search it from start to before that element.

For 3 2 1 output should be -1 3 3 ?

yeah this is correct

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.