In this approach we initially put two pointers: s (slow) and f (fast) at the head of the given linked list as shown in figure 2.
For every 1 step of s pointer, the f pointer moves 2 steps (see figure 3).
This means that the speed of the 'f' pointer is twice that of the 's' pointer. So when the f pointer reaches the end, then the s pointer would be at the mid of the linked list (figure 4).
Hence, when 'f' points at the end node, then the node at the 's' pointer is the mid.
Meditate on the fact that 'f' pointing at the last node can be described as f.next=null which means that the position of f pointer when there is no node after it.
We have learnt the algorithm for this question, now let's code it quickly.