What is wrong with the code?

Priyam, instead of returning a node, from the intersection function, you can write a int function, and simply return the data of the linked list…since its also asked in the code to return -1, if the linked list doesn’t have any intersection point.

Pls use the reference function as :

int intersection(nodehead1,nodehead2,int N1,int N2)
{
int len1=N1;
int len2=N2;
int diff;
if(len2>len1)
{
diff=len2-len1;
}
else
{
diff=len1-len2;
}
if(len2>len1)
{
for(int i=0;i<diff;i++)
{
head2=head2->next;
}
}
else
{
for(int i=0;i<diff;i++)
{
head1=head1->next;
}
}
while(head1 != NULL && head2 != NULL)
{
if(head1->data != head2->data)
{
head1 = head1->next;
head2 = head2->next;
}
else if(head1->data==head2->data)
{
return head1->data;
}
}
return -1;
}