This video is part of Stack and Queues section under GFG SDE Sheet.
In this problem, we have to Implement a Queue using 2 stacks s1 and s2 .
A Query Q is of 2 Types
(i) 1 x (a query of this type means pushing 'x' into the queue)
(ii) 2 (a query of this type means to pop element from queue and print the poped element)
Note :- If there is no element return -1 as answer while popping.
Example :
Input:
5
1 2 1 3 2 1 4 2
Output:
2 3
Explanation:
In the first testcase
1 2 the queue will be {2}
1 3 the queue will be {2 3}
2 poped element will be 2 the queue
will be {3}
1 4 the queue will be {3 4}
2 poped element will be 3.
Try it out before watching the implementation of the problem in the video. We recommend watching the video, even if you can solve the problem. You may discover something new. All the best!!!
Do check out:-
Article: https://www.geeksforgeeks.org/queue-using-stacks/
Problem: https://www.geeksforgeeks.org/problems/queue-using-two-stacks/1
SDE Sheet Link: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/