I am getting a segmentation fault
hey the logic for the question is very simple that you can do this by array indexing .because by array indexing you can talk about the element from the array.
you will run the loop for n times i.e the size of the array and in that you will check if the stack is not empty and if the element at the top of the stack is less then the element int the array at that position i.e ith of the loop then you can pop and print the ith element of the array .
there is no need of the else in this .
you need to just push the index in the stack.
and when the loop will be over then you will do the condition till the stack gets empty you can do or print -1 .
but in this question as there is one circular test case as well .
so you need to separately check if the first element of the arrar is greater then the last then the last output of the array should be the first element .