Your question is Kafka-Style Queue Capacity Simulation. 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.
RBC Online Banking receives requests that require processing by a single worker. Given each request's arrival timestamp and processing duration, simulate a queue whose total capacity is four requests, including the request currently being processed.
Requests are provided in nondecreasing timestamp order. When a request arrives, remove every previously accepted request that has completed by that timestamp. If fewer than four requests remain in the system, accept the new request and schedule it after all currently queued work. Otherwise, drop it.
Return the number of accepted requests and dropped requests as [accepted, dropped].
Implement process_rbc_requests(processing_times, timestamps), where both inputs are arrays of integers of equal length. processing_times[i] is the duration of request i, and timestamps[i] is its arrival time. A request completing exactly at another request's arrival timestamp is removed before the new request is considered. The worker processes requests in arrival order.
def process_rbc_requests(processing_times, timestamps):