Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Implement Queue Using Stacks
00:00
5 left

Implement Queue Using Stacks

EasyPython

Problem

Implement a queue using two stacks. Create a class MyQueue that supports push(x) to add an integer to the back of the queue, pop() to remove and return the front element, peek() to return the front element without removing it, and empty() to return whether the queue is empty. All operations should behave like a standard FIFO queue.

Constraints

  • 1 <= x <= 10^9
  • At most 100 calls will be made to push, pop, peek, and empty
  • All calls to pop and peek are valid

Function Signature

def process_queue_operations(operations, values):
Interviewer

Your question is Implement Queue Using Stacks. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.