Question
Several threads each need to acquire a set of locks. To avoid deadlock, all threads must acquire locks in one consistent global order. You are given a list of thread requirements, where each requirement lists pairs [x, y] meaning 'in this thread, lock x is acquired before lock y'. Treat these as ordering constraints over all distinct locks. Return a single global lock-acquisition order (a list of lock ids) consistent with every constraint; among valid orders, return the one that is lexicographically smallest by lock id. If the constraints are contradictory (cyclic), no safe order exists — return an empty list.
global_lock_order(constraints: list[list[int]]) → list[int][[[1,2],[2,3]]]out[1,2,3]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.
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.