Circular link list

for dummy test my code is runing fine but for test cases it is showing wrong output

Hello @Harsh_aggarwal,

The linked list you have formed is structurally linear.
There is no actual loop or cycle in it.
Thus, the fast and slow pointers will not work for the linked list you have created.

Solution:

  1. just look for the repeating element in your linked list and break it from there to remove cycle.
  2. to apply two pointers approach that you have written, create a cycle in your linked list.
    You can refer to this code I have corrected earlier:
    https://ide.codingblocks.com/s/215583

Hope, this would help.
Give a like if you are satisfied.

how to form this type of link list

Hello @Harsh_aggarwal,

You can refer to the code i have shared in my previous reply and let me know if you face any issue.

All you have to do is to check the repeating element and then make a loop or cycle in the linked list.

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.