Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Producer-Consumer with Circular Queue
00:00
5 left

Producer-Consumer with Circular Queue

HardPython

Problem

Solve a producer-consumer problem: implement a runnable circular queue (initial size 10) on the whiteboard, and design how it resizes dynamically when 90% of the time it holds 7-8 elements but 10% of the time must hold 500 without losing data.

Asked in the Round 3 (onsite) stage.

Implement def circular_queue_operations(operations):. Each operation is ['enqueue', value], ['enqueue_many', values], ['dequeue'], ['size'], or ['capacity']. Return outputs from dequeue, size, and capacity in execution order. Empty dequeue returns None. Start with capacity 10, double when full, and halve when usage reaches at most 25%, never below 10. Preserve FIFO order during resizing.

Constraints

  • 1 <= len(operations) <= 2000
  • Each operation is valid and has the required operands
  • Queue values are integers
  • The initial capacity is 10
  • Capacity doubles when full and halves at or below 25 percent occupancy, never below 10

Function Signature

def circular_queue_operations(operations):
Interviewer

Your question is Producer-Consumer with Circular Queue. 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
Sign up free to run your codeLog inLn 2
Run your code to see test output here.