Cycle detection and removal

My code is not passing all the test cases,help needed.
Also please tell the problem in my approach.

hello @56amrut.bhokardankar
u r not removing detected cycle.

Then please help me to do that

image
here u r assuming that both pointer will meet at start of circle . which is not always.

First detect there is cycle or not using simple two pointer.
now if no cycle present return false otherwise.

reinitialse slow pointer with head .
and move both pointer one step till slow->next=fast->next;
once the condition meet
fast->next=NULL
and return false

image

1 Like

Thanks sir it works fine