Code Room
CodingHardcod-g1016
Subject Concurrency dining philosophers lock orderingLevel Mid–Senior~30 minCommon in Concurrency interviewsIndustries Software development, Technology

Question

N philosophers sit in a circle; philosopher i needs forks i and (i+1) mod N. To avoid deadlock, each philosopher acquires forks using the resource-hierarchy rule: always pick up the LOWER-numbered fork first, then the HIGHER-numbered one. You are given `eat_order`, the order in which philosophers attempt to start eating. A philosopher can begin eating only if BOTH required forks are currently free; otherwise the attempt fails and is skipped (no waiting, no partial acquisition). A philosopher who eats acquires both forks and never releases them in this simulation. Process eat_order in sequence and return the list of philosopher ids who successfully ate, in the order they ate.

Implement
philosophers_eat(n: int, eat_order: list[int]) → list[int]
Examples
in[3,[0,1,2]]out[0]
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.

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.

Run or narrate your approach, then ask the coach.