Bounded blocking queue simulation

Write codeMedium30 minAmazon and Microsoft style

Your task

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].

Examples

bounded_queue_sim(cap: int, events: list[str]) -> list[int]
Example 1
Inputbounded_queue_sim(2, ["P", "P", "P", "C"])
Output[1, 1, 0, 1]