Counting semaphore simulator
Your task
Simulate a counting semaphore that starts with permits available permits and a maximum cap of permits (it can never exceed its initial value). You are given a list of ops, each a string "A" (acquire one permit) or "R" (release one permit). An "A" succeeds and is granted only if at least one permit is available, decrementing the count; otherwise it is rejected. An "R" returns a permit, incrementing the count but never above the cap (an over-release is ignored, leaving the count unchanged). Process ops in order and return a pair [granted, final_available] where granted is the number of successful acquires and final_available is the permits remaining at the end.
Examples
simulate_semaphore(permits: int, ops: list[str]) -> list[int]Example 1
Input
simulate_semaphore(2, ["A", "A", "A", "R", "A"])Output
[3, 0]