Array With Two Stacks

easy
1. Your task is to implement 2 stacks in one array efficiently.
 2. Input in the driver code is of 4 Types
 	 (i)    1 1 x    (input of this type means  pushing 'x' into the stack 1)
 	 (ii)   1 2     (input of this type means to pop element from stack1  and print the poped element)
 	 (iii)  2 1 x  (input of this type means pushing 'x' into the stack 2)
 	 (iv)  2 2     (input of this type means to pop element from stack2 and print the poped element)

Input Format

The first line contains an integer 'N' denoting the number of operations. The second line contains the inputs.

Output Format

The output for each test case will be space separated integers having -1 if the stack is empty else the element popped out from the stack.

Constraints

1 <= N <= 100
 1 <= x <= 100

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
6
1 1 2 1 1 3 2 1 4 1 2 2 2 2 2
Output
3
4
-1
Previous
Swap Kth Node From Beginning And End In Linked List
Next
Decoding A String

Related Questions