Stack & Queue 3: Queue using two stacks | Must Do Coding Questions | GeeksForGeeks

Published: 30 July 2021
on channel: Krishna Teaches
762
19

This video contains Must Do Coding Questions for Companies like Amazon, Microsoft, Adobe, …
from geeksforgeeks platform.

website link:
https://www.geeksforgeeks.org/must-do...

Topics covered in this video series are:
1.Arrays
   • 1.1 ARRAYS | Must Do Coding Questions  
2.String
   • 1.2 STRING | Must Do Coding Questions  
3.Linked List
   • 1.3 LINKED LIST | Must Do Coding Questions  
4.Stack and Queue
5.Tree and BST
6.Heap
7.Recursion
8.Hashing
9.Graph
10.Greedy
11.Dynamic Programming
12.Divide and Conquer
13.Backtracking
14.Bit Magic

Stack and Queue:
3: Queue using two Stacks:
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)

Example 1:
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.

Example 2:
Input:
4
1 2 2 2 1 4

Output:
2 -1

Explanation:
In the second testcase
1 2 the queue will be {2}
2 poped element will be 2 and
then the queue will be empty
2 the queue is empty and hence -1
1 4 the queue will be {4}.

Code Link:
https://github.com/krishna-gavas/Comp...

Intro Music :
   • Video  p


On this page of the site you can watch the video online Stack & Queue 3: Queue using two stacks | Must Do Coding Questions | GeeksForGeeks with a duration of hours minute second in good quality, which was uploaded by the user Krishna Teaches 30 July 2021, share the link with friends and acquaintances, this video has already been watched 762 times on youtube and it was liked by 19 viewers. Enjoy your viewing!