Find the greater element

I couldn’t pass the first test case whats wrong with the code

can you please share the code?

There are multiple errors in your code.

  1. you fixed the size of stack to 100000 while array length can be 1000000. so your stack size should be atleast 1000000.(for the case when array is already in decreasing order)
  2. you should not print the answer instantly in while(element<next){} as the order can possible mix up. think for eg. 22 20 21… so you must store the answer in different array in correct order.(to get correct order, you need to store the indices of element in the stack as well, so when you pull element, you will have its position as well).
    print this answer array in the last.
  3. once you iterate whole array, your stack will have elements in decreasing order. now as question says the array is circular, the next greater element of all the elements left in stack is the bottom of stack(largest element). and the largest element has no next greater element.

Thanks.

Can you help me out ?

fix above three points carefully and you will get your answer.Let me know if you still stuck.
Thanks.