No able to figure out error in intersection of linked list

Node *intersectionOfTwoLinkedLists(Node *headA, Node *headB)
{
if (headA == NULL || headB == NULL) {

    return NULL;
}
    
    Node* l1= headA;
    Node* l2= headB;
    int c1=0;int c2=0;
    while( l1!=l2 && l1!=NULL && l2!=NULL)
    {
        l1=l1->next;
        l2=l2->next;
        
        if(l1==NULL)
        {
            if(c1==0)
            l1=headB;
            else
            break;
            c1++;
        
        }
        if(l2==NULL)
        {
            if(c2==0)
            l2=headA;
            else
            break;
            c2++;
        }
    }
    
    if(l1==l2)
    return l1;
    else
    return NULL;

}

Hi Vibhu. Pls share ur code on ide(https://ide.codingblocks.com/) and share link.
other wise it is not clear properly.

Hi. ur logic is not right. refer this https://ide.codingblocks.com/s/581582

refer this for complete solution https://ide.codingblocks.com/s/581597
hope it clears all ur doubts

please check our code once there is some error

Hi Vibhu. click on submit button and check. it will pass all test case. it might be showing this error as u wouldn’t have give any sample input.

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.