Why my 2 text case is wrong

Its mentioned in the question that you are supposed to print -1 if there is no intersection point between the linked list… So for that either you can use a separate function of return type int…
and you can modify your approach as , :

int intersection(node *a,node *b)
{
int len1=count_list(a);
int len2=count_list(b);
int diff;
if(len2>len1)
{
diff=len2-len1;
}
else
{
diff=len1-len2;
}
if(len2>len1)
{
for(int i=0;i<diff;i++)
{
b=b->next;
}
}
else
{
for(int i=0;i<diff;i++)
{
a=a->next;
}
}
while(a!=NULL && b!=NULL)
{
if(a->data!=b->data)
{
a=a->next;
b=b->next;
}
else if(a->data==b->data)
{
return a->data;
}
}
return -1;
}