Read write lock simulator
Your task
Simulate a non-blocking read-write lock. Multiple readers may hold the lock simultaneously, but a writer needs exclusive access (no readers and no other writer). You are given a list of ops, each [actor, action] where action is one of "RL" (acquire read lock), "RU" (release read lock), "WL" (acquire write lock), "WU" (release write lock). An acquire that cannot be granted right now is rejected (skipped, the actor does not retain anything). Specifically: "RL" succeeds if no writer holds the lock; "WL" succeeds only if there are zero active readers and no writer. Releases of a lock the actor doesn't hold are ignored. Process ops in order and return the number of operations that were successfully granted (acquires) or applied (valid releases).
Examples
rw_lock_grants(ops: list[list]) -> intrw_lock_grants([[1, "RL"], [2, "RL"], [3, "WL"], [1, "RU"], [2, "RU"], [3, "WL"]])5