Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Custom Stack or Queue

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

Your question is Custom Stack or Queue. 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

How would you implement a custom stack or queue using basic arrays or linked lists?

Implement process_operations(mode, operations), where mode is either "stack" or "queue". Each operation is an array such as ["push", value], ["pop"], ["enqueue", value], or ["dequeue"]. Return the values produced by removal and peek operations in order. Return None for removal or peek operations on an empty structure.

Use a custom implementation rather than Python's built-in queue classes. The structure should support constant-time insertion, removal, and peek operations.

Constraints

  • mode is either "stack" or "queue"
  • 1 <= operations.length <= 10^4
  • Each operation is valid for the selected mode
  • Values may be integers, strings, or null
  • An empty pop, dequeue, or peek returns None

Function Signature

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