Node *intersectionOfTwoLinkedLists(Node *l1, Node l2)
{
/Code here/
int x = 0;
Node temp = l1;
while (temp != NULL)
{
x++;
temp = temp->next;
}
temp = l2;
int y = 0;
while (temp != NULL)
{
y++;
temp = temp->next;
}
if (x > y)
{
int diff = x - y;
while (diff--)
{
l1 = l1->next;
}
}
else if (y > x)
{
int diff = y - x;
while (diff--)
{
l2 = l2->next;
}
}
while (l1->data != l2->data)
{
l1 = l1->next;
l2 = l2->next;
}
return l1;
}