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
Circular Buffer for Embedded
00:00
5 left

Circular Buffer for Embedded

MediumPython

Problem

An Amazon Echo device uses a fixed-size memory region to buffer events before they are processed. Implement a circular buffer with overwrite-oldest behavior: when a push occurs on a full buffer, discard the oldest element and retain the new one.

Implement process_circular_buffer(capacity, operations). Each operation is an array whose first element is a command:

  • ["push", value]: insert one integer.
  • ["push_many", values]: insert all integers in order.
  • ["pop"]: remove and return the oldest value, or None if empty.
  • ["peek"]: return the oldest value without removing it, or None if empty.
  • ["snapshot"]: return all values from oldest to newest.
  • ["size"]: return the current number of stored values.
  • ["is_full"]: return whether the buffer is full.

Return an array containing the result of every operation that produces a value: pop, peek, snapshot, size, and is_full. Push operations produce no result.

Constraints

  • 1 <= capacity <= 10^5
  • 1 <= len(operations) <= 10^5
  • The total number of values in all push_many operations is at most 10^6
  • Pushed values are integers in the range -10^9 through 10^9
  • Every operation uses a valid command format

Function Signature

def process_circular_buffer(capacity, operations):
Interviewer

Your question is Circular Buffer for Embedded. 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.