Time Complexity of the Code

Will the time complexity of the code would be O(n)?
Link of the code:-https://ide.codingblocks.com/s/457501.

hello @Sakshi2004
no its approx o(n^2) because u have another loop inside else block …

How can we further optimise it?

first try to solve next greater element in the left and next greater element in right problems for linear array.
hint -> try to maintain sorted stack.

here in this problem the array is circular so solution will be extension of above approachs.

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.