https://ide.codingblocks.com/s/99510 I’m getting TLE in this code. please help me to debug. thankyou.
Circular linked list(detect and remove loop)
Hello,
There are two major flaws in your code which is causing TLE:
- Your input Format, i.e. you are only reading the first number of the input sequence as n.
- 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:
- Traverse all the nodes of link list one by one.
- Store the data of the nodes
- check if it starts repeating.
- The point when any of the data repeats, limit the list to that node.