Dining philosophers fork allocation

Write codeHard30 minMicrosoft and Apple style

Your task

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.

Examples

philosophers_eat(n: int, eat_order: list[int]) -> list[int]
Example 1
Inputphilosophers_eat(3, [0, 1, 2])
Output[0]