Code RoomBounded blocking queue simulation
MediumPrep Room Coding #303

Bounded blocking queue simulation

CodingConcurrencyDistributed systemsMid–Senior~30 min

Simulate a bounded blocking queue with one producer and one consumer over discrete ticks. The queue has capacity 'cap'. events is a list of strings, one per tick, each 'P' (producer attempts to enqueue one item) or 'C' (consumer attempts to dequeue one item). A 'P' that finds the queue full is BLOCKED (no item added, counts as a blocked-produce). A 'C' that finds the queue empty is BLOCKED (counts as a blocked-consume). Successful operations change the queue size. Return [items_consumed, blocked_produces, blocked_consumes, final_queue_size].

Implement
bounded_queue_sim(cap: int, events: list[str]) → list[int]
Examples
in[2,["P","P","P","C"]]out[1,1,0,1]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 30 min
InputExpectedGot
[2,["P","P","P","C"]][1,1,0,1]not run yetsample