let’s assume a pointer p which contain the prev node of fast so our solution is as follows
if(fast==slow){
slow->next=head;
slow=slow->next;
node *p;
p->next=fast;
fast=fast->next;
if(fast==slow){
p->next=NULL;
}
is this approach correct?
Floyd's Cycle removal
@Vivek-Pandey-2129725577345937
You should always mention the context (Timing in the video, or the problem statement, or some details) of the query.
The correct approach would be
node*p = head;
while(p->next != fast) p = p->next; // Getting to the previous node of fast
s = head;
while(fast!=slow){
slow=slow->next;
p = fast;
fast = fast->next
}
p->next = null;
Let me know if you till need any help.
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.