Note: If a pop operation is used in an empty stack nothing happens to the stack, but you have to print -1.
The first line of the input contains ‘T’ denoting the number of test cases.
The first line of each test case contains ‘Q’ denoting the number of queries.
In the next Q lines input is either of the types :
Id 0: where ‘id’ is the index of the stack ( out of the three ) in which we have to work on, 0 means we have to pop a top element from the stack.
Id 1 ele: where ‘id’ is the index of the stack ( out of the three ) in which we have to work on, 1 means we have to push ‘ele’ element on top of the stack.
For each query of type 0, If the stack is non-empty print the removed element.
If a stack is empty print -1.
Print each element in the new line.
1 <= T <= 3
0 <= Q, ele <= 10^5
0 <= id <= 2 , denoting one of the three stack
Time Limit : 1 sec
Postorder Traversal
Min Stack
Stock Span
Hills and Soldier
Hills and Soldier
Next Greater Element II