Work order severity
A field service desk dispatches work orders from a queue that operations reorders by severity. ids holds the work order numbers in the order they arrived, severities holds the severity label each one carries, and those two lists are the same length. ranking is the configured severity order, most pressing first, and holds no repeats. A work order whose label appears in ranking takes that label's position. A label the configuration never mentions is less pressing than every listed one, and labels match exactly, so a difference in capitalisation makes a label unknown. Work orders sharing a position keep the order they arrived in, and the unknown ones do the same among themselves. Return the work order numbers in dispatch order. An empty queue returns an empty list, and an empty ranking leaves the arrival order untouched.
dispatch_work_orders(ids: list[str], severities: list[str], ranking: list[str]) → list[str][["WO-1","WO-2","WO-3","WO-4"],["routine","urgent","urgent","cosmetic"],["urgent","routine"]]out["WO-2","WO-3","WO-1","WO-4"][["WO-8","WO-2","WO-5"],["routine","urgent","routine"],[]]out["WO-8","WO-2","WO-5"][["W1","W2","W3","W4"],["low","high","low","high"],["high","medium","low"]]out["W2","W4","W1","W3"]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.
[["WO-1","WO-2","WO-3","WO-4"],["routine","urgent","urgent","cosmetic"],["urgent","routine"]]["WO-2","WO-3","WO-1","WO-4"]not run yetsample[["WO-8","WO-2","WO-5"],["routine","urgent","routine"],[]]["WO-8","WO-2","WO-5"]not run yetsample[["W1","W2","W3","W4"],["low","high","low","high"],["high","medium","low"]]["W2","W4","W1","W3"]not run yetsample