• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
January 10, 2024 |510 Views
SDE Sheet - Stack using two queues
Description
Discussion

This video is part of Stack and Queues section under GFG SDE Sheet.

In this problem, we have to Implement a Stack using two queues q1 and q2.

Example :

Input:
push(2)
push(3)
pop()
push(4)
pop()
Output: 3 4

Explanation:
push(2) the stack will be {2}
push(3) the stack will be {2 3}
pop()   poped element will be 3 the 
       stack will be {2}
push(4) the stack will be {2 4}
pop()   poped element will be 4 

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/implement-stack-using-queue/
Problem: https://www.geeksforgeeks.org/problems/stack-using-two-queues/1
SDE Sheet Link: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/

Read More