Not able to clear last test case

here is the link of my code : https://ide.codingblocks.com/s/396261

Hello @great please wait i am checking your code:

Hello @great please see this updated code:


if you have any further doubt you can ask here:
Happy Learning!!

Actually I am still not able to figure out why you make the following changes, Also please try to make changes in my own code (m just failing one test case) and please provide reasoning for the same

@great if you can see then you can observe that thing that i have made changes in your code only.
and yes when you have found cycle then also you are not remooving that cycke when you have not even completed the code then how can you expect that your code will pass all the test cases?
you dont only have to return true or false.
but if there is cycle then you have to remove it as well.
Happy Learning!!

Hey Tushar,
I am sorry to say that I don’t think so, you have given 2 minutes to my code. If you see it clearly (and carefully) , you can see that I had made a new function for removing the cycle which I am calling if cycle is found and due to which only I am able to clear all the testcases except one for which I have raised the query. Also, coming to your point that I have not completed the code, how can I am able to pass 9/10 testcases with not writing code for cycle removal. It is my request to cb that please try to debug the problem in the individual’s code rather than just providing the solution which can be found in any site(prep site );

@great in this question it is mentioned that you have to write the code there only how can i know that you have made changes somewhere in the other part as well.
and also we dont have access to your portal.
i think try to make change in line 95 in your code:
it should be fast->next->next;
for comparing fast==slow.
the code which i have given to you in that i have pasted your function logic and then completed its not that i have given you the new code.
if you have any other doubt you can ask here:
Happy Learning!!

Hey Tushar, I don’t think so that would work because if you follow video on floyd cyle given in this course , (x=z logic) . When we found fast==slow we decrease the speed of fast pointer to 1x from 2x (for making x=z) and make slow pointer to move to head. Also I have tried code using your logic and it is failing

Also the code given by you earlier is not correct (not able to pass testcases). Please see to it at your earliest

@great
Hi.
First of all, if it is specified that you are not to make any changes to the code below that big comment and that you are required to only write code in the given function, you should follow these constraints. The TA is not expected to check the entire code for such problems but rather only the designated function since it is clearly mentioned in the problem statement as well.

Coming to the issue with your code , the issue is in this line

while(fast->next!=NULL and fast!=NULL)

As you can see, you are checking whether fast is NULL or not after you have checked for its next to be NULL.
Consider the case when the ‘fast’ pointer is actually pointing to NULL. Since there is no ‘next’ defined for NULL, the first check will throw an error. It will never even reach the second check.
To fix the issue, you only have to invert the order of your checks.

while(fast!=NULL and fast->next!=NULL)

This will check the conditions in right order and ensure that we do not try to access invalid memory and thus prevent th error.
This modification will also help you pass the only remaining testcase.

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.