Bad Test Cases
I think the TCs aren\'t designed well\n\nA simple solution with a single semaphore is able to pass the TCs under 10ms (better than 92% of java solutions)\n whic
I think the TCs aren\'t designed well\n\nA simple solution with a single semaphore is able to pass the TCs under 10ms (better than 92% of java solutions)\n* which leads to starvation (same philosopher may be entering the critical section again and again while some may not be getting a chance at all)\n* under utilization of resources (philosopher with id=2 also gets blocked when philosopher with id=0 acquires the semaphore, but ideally he can pick up his forks and start eating)\n\n```\nclass DiningPhilosophers {\n    Semaphore s = new Semaphore(1);\n\n    public DiningPhilosophers() {\n        \n    }\n\n    // call the run() method of any runnable to execute its code\n    public void wantsToEat(int philosopher,\n                           Runnable pickLeftFork,\n                           Runnable pickRightFork,\n                           Runnable eat,\n                           Runnable putLeftFork,\n                           Runnable putRightFork) throws InterruptedException {\n        \n        s.acquire();\n        pickLeftFork.run();\n        pickRightFork.run();\n        eat.run();\n        putLeftFork.run();\n        putRightFork.run();\n        s.release();\n    }\n}\n```
['Java']