Intersection point in linked list


showing run time error

Hey @divyam_13
Did 3 changes and mentioned them in comments

Node *intersectionOfTwoLinkedLists(Node *l1, Node *l2)
{
    if(l1==NULL)
    {
        return NULL;
    }
    if(l2==NULL)
    {
        return NULL;
    }
    Node*p=l1;
    Node*q=l2;
    Node*temp=l1;
    int len1=0;
    while(temp!=NULL)
    {
        len1++;
        temp = temp->next;
    }
    int len2=0;
    Node*temp1=l2;
    while(temp1!=NULL)
    {
        len2++;
        temp1 = temp1->next; //updated this (temp1) instead of temp
    }
    int d=abs(len1-len2);
    if(len1>len2)
    {
        int cnt=0;
        while(cnt<d)
        {
            p=p->next;
            cnt++;//added this
        }
         while(p!=q)
         {
             p = p->next;
             q = q->next;
         }
          return p;      
    }
    else
    {   int cnt=0;
        while(cnt<d)
        {
            q=q->next;
            cnt++;//added this
        }
         while(p!=q)
         {
             p = p->next;
             q = q->next;
         }
          return q;
    }     
    
    /*Code here*/
}

If this resolves your query then please mark it as resolved :slight_smile: