Please point out my mistake

Hello @sattyrajpoot39,

The following logic would not work in the linked list you have created.
while(fast!=NULL||fast->next!=NULL)
{
fast=fast->next->next;
slow=slow->next;
if(fast==slow)
{
break;
}

    }

REASON:
The linked you have created is linear. There is no actual cycle in it.
So, fast and slow pointers will never meet.

Solution:

  1. Check value at each node of linked list.
  2. If any value repeats which marks the start of cyle, break the linked list from there.
  3. Then, print the modified linked list

Hope, this would help.
If you still have doubts, feel free to ask.
Give a like, if you are satisfied.

so how to approach,i’m not able to code out the approach

You can refer to this for the implementation of above specified logic.

but your logic has some flaw it’s not giving req o/p

Can you point out any mistake?
It will help you in solving the problem.

BTW share your modified code.

Yes I can,but I thought you should have got it ,nonetheless i will share the code

https://ide.codingblocks.com/s/105282 you didn’t increment temp1 ptr after each itrn,i did but still getting tle

I wanted you to point it out because it an essential part of coding, to find mistakes in a code.:sweat_smile:
This really helps in long run.

BTW i have modified the logic:

I have added the necessary comments in the code for better understanding.

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

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.