Circular linked list(detect and remove loop)

https://ide.codingblocks.com/s/99510 I’m getting TLE in this code. please help me to debug. thankyou.

Hello,
There are two major flaws in your code which is causing TLE:

  1. Your input Format, i.e. you are only reading the first number of the input sequence as n.
  2. In the print() function, the while loop will never terminate.

Also, in your code you are detecting the cycle but not removing it.

Hope, this would help.

https://ide.codingblocks.com/s/99586 TLE’s have been removed. but I’m not getting the output. kindly help.

This is happening because the logic you have applied is wrong.

While detecting and removing loop:

  1. Traverse all the nodes of link list one by one.
  2. Store the data of the nodes
  3. check if it starts repeating.
  4. The point when any of the data repeats, limit the list to that node.