Intersection link list

to solve this question first we have to create y shape link list…how to create that

not working for one test caes

Dakshi, pls use the approach as,
int intersection(node* head1, node* head2,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;

}