Please provide code solution of circular array as i did not understand in the video

please help in the given question

Hey Harshit, the first way to do the problem is simple brute force, for every element i scan i+1 to n then 0 to i-1 to find its next greater element , it would be accepted.

Second, method is to use a stack in stack store index of element. Start with the right hand side of the array, for every element a, pop the stack while array[stack[top]]<=a, now at the top we will have element index that is greater than a so make it its next greater element, if stack becomes empty make -1 as next greater, after reaching the left end again go back to right end(without disturbing the stack) and follow same steps.
I hope this help, try to implement it, if you find it difficult to implement then I will provide code.

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.