Link - https://ide.codingblocks.com/s/419805
I am getting error in execution. Please help.
Intersection point in a linked list
Hey @meet1708 the problem you have mentioned in doubt is of intersection point of linked list, and your code doesn’t match with the problem , you have doubt in intersection point of linked list?
i have edited the link. plz check
Hey @meet1708 it’s logic error, see if this is 2 merged linked list and bigger linked list has length 6 and shorter 5 then first find the difference which in this case is 1, the linked list which is bigger in size . In that linked list travel to that much node , here you will reach at 10th node.
Now one pointer is at 10th node and another is at 5th node, now increment node by node and return that node which proves ptr1==ptr2
Attaching code for reference
Node *intersectionOfTwoLinkedLists(Node *l1, Node *l2)
{
/*Code here*/
int len1=length(l1);
int len2=length(l2);
int d=abs(len1-len2);
if(len1>len2)
{
Node*tail=l1;
while(d--)
{
tail=tail->next;
}
Node*tail2=l2;
while(tail!=NULL&&tail2!=NULL)
{
tail=tail->next;
tail2=tail2->next;
if(tail==tail2)
{
return tail;
}
}
}
if(len1<len2)
{
Node*tail=l2;
while(d--)
{
tail=tail->next;
}
Node*tail2=l1;
while(tail!=NULL&&tail2!=NULL)
{
tail=tail->next;
tail2=tail2->next;
if(tail==tail2)
{
return tail;
}
}
}
return NULL;
}
My approach is different I am using 2 pointer approach.
Reference - https://www.geeksforgeeks.org/write-a-function-to-get-the-intersection-point-of-two-linked-lists/
Method 8
Check this, it won’t work as the method they have suggested is implemented here only. You can check and follow the approach i have share with you.
Check now , just a little modification. Although the concept is right. But you have to implement it like this.
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.

