Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Queue Implementation From Scratch

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

Your question is Queue Implementation From Scratch. 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 basic data structures.

Implement def implement_queue(operations):, where operations is a list of command lists and each command is enqueue with a value, dequeue, peek, or is_empty; return a list containing results from non-enqueue commands. dequeue and peek return None when empty, is_empty returns a boolean, and operations must preserve FIFO order. Examples: [["enqueue", 4], ["enqueue", 7], ["dequeue"], ["peek"]] returns [4, 7]; ["is_empty"] returns [True]. Constraints: at most 10^4 operations, integer values, and valid commands only.

Constraints

  • 0 <= operations.length <= 10^4
  • Each operation is a valid command list.
  • An enqueue operation has the form ["enqueue", value].
  • Values are integers.
  • Dequeue and peek return None when the queue is empty.

Function Signature

def implement_queue(operations):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output