Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Implement a Circular Buffer

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

Your question is Implement a Circular Buffer. 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 circular buffer.

Asked in the coding stage for the Meta Reality Labs Embedded SW Engineer, Firmware interview, in the same round as the memcpy question. Reported follow-ups included “why” and “what” questions about implementation choices.

Contract

Implement circular_buffer(capacity, operations). Each operation is an array: ["enqueue", value], ["dequeue"], ["peek"], ["is_empty"], or ["is_full"]. Return one result per operation. enqueue returns true or false, dequeue and peek return a value or null, and status operations return booleans. The buffer must preserve FIFO order and reuse storage after wraparound.

Constraints

  • 1 <= capacity <= 10^4
  • 1 <= len(operations) <= 10^4
  • Each value supplied to enqueue is an integer
  • Operation names are valid and use the specified formats

Function Signature

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