What is the problem in this code?

hello @Ak07
image
use slow ->next!=fast->next;
because we need to stop one node before the cycle
so that we can simply do fast->next=NULL to remove cycle.
while loop after this condtion is redundant u can remove that.

also try to submit ur code here.
https://hack.codingblocks.com/app/contests/1350/1307/problem
because input / output is already handled ,u just need to write code for cycle detection and removal

That is ok but then what do I do for this problem which is in the course

you can submit there as well

on hackerblocks it passed all cases, but in course it is not,
also I guess they are two different problems altogether

have u submitted same code at both places?

yes, exactly same code

please share ur updated code using cb ide ,i will check

check this->

you were not reading input completely.
image
here dont return read till end.
so replace return with continue

I didn’t write this input function it was already written, but as you suggested that in hackerblocks the input output is already handled I just wrote for cycle detection and removal. I didn’t understand this input function as I have not studied hash. Hence I had started by writing my own build function, if possible can you please guide me for this problem on the code that I wrote on my own from scratch

see basically u are searching whether the entered number is already existing in list or not , if it is then u are making a cycle otherwise u r adding it to the tail.

same thing is happening in the previous code .instead of searching we have stored the information in map.
so that we dont have to search again n again.

due to so many search operations ur code might give tle.
but logically ur code is correct ( after making changes that i have suggested very first time).

Thanks a lot, but it is still only passing 1/3 test cases

r u sure ,
in my machine it is passing all
image

sorry, my bad, yes its passing all 3, Thanks