Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Implement Queue Using Stacks

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Implement Queue Using Stacks. Start with the requirements on the right.

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.

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):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output