Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Circular Array Queue

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

Your question is Circular Array 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

SoFi may need to process payment events in arrival order using a fixed-size in-memory buffer. Implement the buffer as a circular array so every enqueue and dequeue operation runs in strict O(1) time.

Write process_queue(operations, capacity). operations is a list of operations, where ['enqueue', value] adds an integer to the queue and ['dequeue'] removes and returns the oldest value. For each operation, append its result to the returned list: True for a successful enqueue, False when the queue is full, the removed integer for a successful dequeue, and None when the queue is empty.

The queue must preserve FIFO order. Do not shift array elements during removal, and do not use Python's collections.deque.

Constraints

  • 1 <= capacity <= 10^5
  • 1 <= len(operations) <= 10^5
  • Each enqueued value is an integer in [-10^9, 10^9]
  • Each operation is either ['enqueue', value] or ['dequeue']

Function Signature

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