Discussion: Issues with Dining Philosopher Problem

The problem with the solution provided in the video by @championswimmer-t here is, what if each philosopher get hold of only one chopstick then they are stuck, neither they can eat nor think :cold_sweat:.
This can happen as follows:
p1 picks up the chopstick on its left by calling wait(chopstick[1]) but before p1 can pick up the chopstick[2]
p2 gets into play and pick up the chopstick[2] but before it can pick up the chopstick[3] p3 comes and get hold of chopstick[3] and so on, such unfortunate switching results in every philosopher having only one chopstick and waiting on the other indefinitely.
What do you think can be a possible solution to it?

The solution to this has been told in the Deadlock prevention strategy video
The solution is if philosophers take the chopstick with lower index first. In this way, in above case, p5 will not take the chopstick[5] because p5 wants to get chopstick[1] first thus it waits and p4 will take the chopstick[5] finish eating and place both the chopsticks[4] and chopstick[5] down and thus circular-wait will not take place.
may be applied as follows:

temp = (i+1)%numOfChopsticks;
if(temp > i)
    first = i;
    second = temp;
else
    first = temp;
    second= i;
wait(first);
wait(second);
//eat
signal(second);
signal(first);
//think