push(X, M): Pushes an element X into the Mth stack. Returns true if the element is pushed into the stack, otherwise false.
pop(M): Pops the top element from Mth Stack. Returns -1 if the stack is empty, otherwise, returns the popped element.
Type 1: for push(X, M) operation.
Type 2: for pop(M) operation.
The first line of input contains three space-separated integers ‘N’, ‘S’ and ‘Q’ denoting the number of stacks, the size of the array and number of queries, respectively.
The next ‘Q’ lines specify the type of operation/query to be performed on the data structure.
Each query contains an integer ‘P’ denoting the type of query.
For query of type 1, the integer ‘P’ is equal to 1 and it is followed by two space-separated integers ‘X’ and ‘M’ denoting the element and stack on which operation is to be performed, respectively.
For query of type 2, the integer ‘P’ is equal to 2 and it is followed by a single integer ‘M’ denoting the stack on which operation is to be performed.
For each query, print the output returned after performing the corresponding operation on the data structure.
You do not need to print anything, it has already been taken care of. Just implement the given functions.
1 <= N <= S <= 1000
1 <= Q <= 10^5
1 <= P <= 2
1 <= X <= 10^5
Time Limit: 1 sec
Where ‘S’ represents the size of the array, ‘N’ represents the number of stacks, ‘Q’ represents the number of queries, ‘P’ represents the type of operation and ‘X’ represents the element.
Postorder Traversal
Postorder Traversal
Min Stack
Min Stack
Min Stack
Min Stack
Min Stack
Min Stack
Min Stack
Min Stack
Stock Span
Stock Span
Stock Span
Hills and Soldier
Hills and Soldier
Hills and Soldier
Hills and Soldier
Hills and Soldier
Next Greater Element II