Bounded buffer simulation

Write codeHard40 minMicrosoft style

Your task

Simulate a deterministic bounded-buffer producer/consumer over a sequence of operations. You are given ops, a list of strings each either 'P' (produce) or 'C' (consume), and an integer cap (buffer capacity). Process ops left to right maintaining a current item count: a 'P' succeeds (count += 1) only if count < cap, otherwise it is a DROPPED produce; a 'C' succeeds (count -= 1) only if count > 0, otherwise it is a STARVED consume. Return a list [produced, consumed, dropped, starved] tallying how many of each outcome occurred.

Examples

simulate_buffer(ops: list[str], cap: int) -> list[int]
Example 1
Inputsimulate_buffer(["P", "P", "C", "P"], 2)
Output[3, 1, 0, 0]