Question
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).
rw_lock_grants(ops: list[list]) → int[[[1,"RL"],[2,"RL"],[3,"WL"],[1,"RU"],[2,"RU"],[3,"WL"]]]out5State 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.
Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.