Code RoomBounded buffer producer consumer
MediumPrep Room Coding #167

Bounded buffer producer consumer

CodingConcurrencyMid–Senior~30 min

Simulate a single bounded buffer of capacity k shared by producers and consumers. You are given an ops list of strings, each either "P" (a producer tries to enqueue one item) or "C" (a consumer tries to dequeue one item). The buffer starts empty. A "P" succeeds only if the buffer is not full; a "C" succeeds only if the buffer is not empty. Operations that would block are dropped (skipped) rather than waiting. Process ops left to right and return a pair [final_size, completed] where final_size is the number of items left in the buffer and completed is the count of operations that succeeded.

Implement
simulate_buffer(k: int, ops: list[str]) → list[int]
Examples
in[2,["P","P","P","C","C","C"]]out[0,4]
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","C","C"]][0,4]not run yetsample