Clear,easy and working solution using Locks. Beats > 90%
IntuitionIf lock for current and adjcent plates are available, can proceed to pick
forks and eat. Else wait for some time and retryApproachComplexity
Time compl
# Intuition
If lock for current and adjcent plates are available, can proceed to pick 
forks and eat. Else wait for some time and retry

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class DiningPhilosophers {
    Lock[] plateLock;

    public DiningPhilosophers() {
        plateLock = new ReentrantLock[5];
        for (int i = 0; i < 5; i++)
            plateLock[i] = new ReentrantLock();

    }

    // call the run() method of any runnable to execute its code
    public void wantsToEat(int p,
            Runnable pickLeftFork,
            Runnable pickRightFork,
            Runnable eat,
            Runnable putLeftFork,
            Runnable putRightFork) throws InterruptedException {

        try {
            //philosopher p left is p+1, right is p+4
            int leftP = (p + 1) % 5;
            int rightP = (p + 4) % 5;

            //lock 3 plates to ensure no fork common is unavailable
            while (true) {

                if (plateLock[leftP].tryLock(5, TimeUnit.MILLISECONDS)) {
                    if (plateLock[p].tryLock(5, TimeUnit.MILLISECONDS)) {
                        if (plateLock[rightP].tryLock(5, TimeUnit.MILLISECONDS)) {

                            pickLeftFork.run();
                            pickRightFork.run();

                            // Thread.sleep(10);
                            eat.run();
                            // Thread.sleep(10);
                            putRightFork.run();
                            putLeftFork.run();

                            plateLock[rightP].unlock();

                            plateLock[p].unlock();

                            plateLock[leftP].unlock();

                            return;
                        } else {
                            plateLock[p].unlock();

                            plateLock[leftP].unlock();

                            // System.out.println(" current p " + p + "not available so reverting for philos::" + p);
                        }

                    } else {
                        plateLock[leftP].unlock();

                        // System.out.println(" right p " + rightP + "not available so reverting for philos::" + p);
                    }

                } else {
                    // System.out.println(" left p " + leftP + "not available for philos::" + p);
                }

                Thread.sleep(20);
            }

        } finally {

        }

    }
}
```
['Java']