Detect and break a loop in singly linked list

plz explain the code for this problem …and also share the code along with the explaination…

@S19LPPP0202 hey try this:

  1. This method is also dependent on Floyd’s Cycle detection algorithm.
  2. Detect Loop using Floyd’s Cycle detection algorithm and get the pointer to a loop node.
  3. Count the number of nodes in loop. Let the count be k.
  4. Fix one pointer to the head and another to a kth node from the head.
  5. Move both pointers at the same pace, they will meet at loop starting node.
  6. Get a pointer to the last node of the loop and make next of it as NULL.
    Here is code for refrence:
    https://ide.codingblocks.com/s/70704
    For pictorial representation see the video of coding blocks.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.