Find loop in a linked list and remove it - PrismoSkills
To find the loop length, move FP and NP once again till they meet.
If loop is of length k, FP and NP will meet again after NP has moved k/2 nodes and FP has moved k nodes.
To find the loop beginning, take two pointers from the list beginning but separated by k nodes. At that time, the first pointer is N-k node from the loop beginning and second pointer is N-k from the loop end. So if we move them till they meet, then they will meet after N-k nodes i.e. at the loop beginning.
Read full article from Find loop in a linked list and remove it - PrismoSkills