Loop detection of a Linked List

I am not able to form a loop in the linked list…

Just traverse the linked list using 2 pointers…if one of them meets the other during the traversal…that means there is a loop in the linked list

Hi Nargis, you are not able to form or DETECT the loop ?

my doubt is to form a loop…
because in the question first we have to take the inputs in such a way that it form a loop…
and then detect it and remove…

Hi Nargis, to form the loop what you can do is everytime you take input, check for if that value is already present in the current list. If yes then then take and point and hence form the list accordingly. From this you will also get the point till where you have to print the list.
Also, this is the most simple way, try to optimize it, the detection part.

Hope this helps :slight_smile:

Hey Nargis,
As you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.