Code RoomRobot fixture deadlock
EasyPrep Room Coding #4841

Robot fixture deadlock

CodingConcurrencyEntry–Mid~16 min

A robot cell avoids gridlock with one rule: every robot must claim fixtures in a fixed global ranking, never doubling back. rank_order lists the distinct fixtures from the one that has to be claimed earliest to the one that has to be claimed latest. trace is the recording of what happened, one line per claim or release, written as "robot|take|fixture" or "robot|drop|fixture". A drop always names a fixture that robot is holding right then, and every fixture in the trace appears in rank_order. A take breaks the rule when the fixture ranks no higher than some fixture the robot is already holding, which includes taking a fixture it holds already. Waiting is not your concern: judge ordering only. Reading the trace top to bottom, return the id of the robot whose take breaks the rule first, or an empty string when nothing does.

Implement
first_lock_order_offender(rank_order: list[str], trace: list[str]) → str
Examples
in[["mesh","spindle","gantry"],["r1|take|mesh","r1|take|gantry","r2|take|spindle"]]out""
in[["mesh","spindle","gantry"],["r1|take|gantry","r1|take|mesh"]]out"r1"
in[["a","b","c"],["t1|take|a","t1|take|c","t1|drop|c","t1|take|b"]]out""
What a strong answer looks like

State 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.

0:00 of about 16 min
InputExpectedGot
[["mesh","spindle","gantry"],["r1|take|mesh","r1|take|gantry","r2|take|spindle"]]""not run yetsample
[["mesh","spindle","gantry"],["r1|take|gantry","r1|take|mesh"]]"r1"not run yetsample
[["a","b","c"],["t1|take|a","t1|take|c","t1|drop|c","t1|take|b"]]""not run yetsample