Approach (Hint :Use Stack)


Step 1: Create an empty Stack and a vector
Step 2: iterate from beginning of given array
Step 3: while stack is not empty and top of stack is greater than or equal to current array element , pop from stack
Step4: if stack is empty after above statement then push -1 in resultant vector else push top of stack in resultant vector
Step 5:push current element in stack
Step 6: iterate till end of array while following steps 3-5