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.
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.
def process_queue(operations, capacity):