Cycle Detetction and Removal

Hi,
This problem seems to follow a different structure than other problems in this course.

There is a lot of code already given, aimed at generating the required cycle that is to be detected and broken.

The question also advises us to not touch any of this code and just write the already defined function for solution.

I have followed the instructions, as i understood them but i cannot figure out how to test my function since it is not clear what type of user input may be entered.

It is also highly unclear where and how a linked list is created, if any, because i cannot seem to get anything out of the buildlist functions and there seems to be no linked list at all.

Please help me figure out how to appraoch this problem, also please see my function at : https://ide.codingblocks.com/s/326935

Note: i have not touched anything other than said fucntion and i cannot figure out how to make this work.

Thanks for your help!

hello @ilovetocode i have made change in your code and now it is printing the right answer and i have given you ine saple test case as well as you asked for it in the description above .


if you dont understand anything please let me know.
i hope i have cleared your doubt .
please mark this as resolved, if you feek your doubt is cleared.
Happy Learning !!

Hi Tushar,
Thanks for your quick response.
I am still facing a couple of issues:

  1. The code you have updated for me is still missing one testcase, please review.

  2. I tried testing your solution with removing the found linked list in the input and it still detects the linked list for some reason, i am unable to understand how this is working.

  3. You have used STL and maps in your appraoch which is new to me and slightly different from the detection code taught in the videos, is there a way to implement this with the slow and fast pointers? as Prateek Bhaiya taught us? any way you could see if my own attempt at this implementation can work?

Thanks again for your assistance.
Cheers!

Hi @tusharaggarwal272,
Just a ping, your solution still doesn’t pass the testcase and im stuck on the doubts mentioned below.
Thanks!

Hello @ilovetocode I will not say that there is no other way to code it but yes definitely other way will be lengthy and will be bit tricky to understand.
In my way I have just mapped the occurrence of the element and checking if it has already been occured or not.

How many test cases were not passed?

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.