Read-write lock writer priority
Your task
Simulate a read-write lock with a writer-priority, non-reentrant policy. requests is a list of [id, mode] where mode is 'R' (shared read) or 'W' (exclusive write), each requesting the lock in order and never releasing until granted-then-immediately-released in grant order. Use this deterministic rule to produce the GRANT order: process requests greedily from a waiting list; multiple consecutive readers can be granted together (and released together) as one batch, but a writer must hold the lock alone. To enforce writer priority, whenever the next waiting request in input order is a writer, it must be granted before any later reader. Concretely: scan the waiting list in order; if the head is a writer, grant just that writer; if the head is a reader, grant the maximal prefix of consecutive readers from the head. Return the list of ids in the order they are granted.
Examples
rwlock_grant_order(requests: list[list]) -> list[int]rwlock_grant_order([[1, "R"], [2, "R"], [3, "W"], [4, "R"]])[1, 2, 3, 4]