Concurrency design problem (paper-only). Threading is not available in the sandbox; the auto-grader validates a simulation of a deadlock-free fork-acquisition order.
Five silent philosophers sit at a round table with bowls of spaghetti. Forks are placed between each pair of adjacent philosophers. Each philosopher must alternately think and eat. However, a philosopher can only eat when they have both the left and right forks. Each fork can be held by only one philosopher at a time. After eating, they need to put down both forks so they become available to others.
Naïve "pick up left then pick up right" deadlocks if every philosopher grabs a left fork simultaneously. You must produce a deadlock-free schedule.
For the auto-grader: given an integer array order of length 5 * meals representing the order in which philosophers 0..4 would like to eat (each value 0..4, each value appears exactly meals times), return an array of the same length giving the order in which they actually eat under the odd-even strategy: philosopher i is allowed to eat next iff neither of their forks is currently held. The simulation processes the wish-list from left to right; if the current wisher's neighbours are eating they are skipped to the back of a waiting queue, and you re-check the queue first on each step.
The output array must be a valid deadlock-free permutation in which no two adjacent philosophers (mod 5) ever appear in adjacent positions of the output.