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

Veröffentlicht am: 30 Juli 2021
auf dem Kanal: 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


Auf dieser Seite können Sie das Online-Video Stack & Queue 3: Queue using two stacks | Must Do Coding Questions | GeeksForGeeks mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Krishna Teaches 30 Juli 2021 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 762 Mal angesehen und es wurde von 19 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!