gives tle in one test case
Code modification
@roopenmangat
Your code would give an error in cases like:
1
0
2
5 10
In such cases no intersection point would be found, so you need to return NULL if no intersection point is found.
So at the end of your function, include a return NULL statement after the while loop. This will return NULL if no intersection point is returned while the execution of the loop. Your fnction would go like:
node * insertionpoint(node* head1,node * head2)
{ node* temp=head2;
while(head1!=NULL)
{
while(head2!=NULL)
{
if(head1->data==head2->data)
{
return head1;
}
head2=head2->next;
}
head2=temp;
head1=head1->next;
}
return NULL;
}
Also, in the main function, while printing the answer, you need to write like:
if(temp)cout<data<<endl;
else cout << -1 << endl;
Coz you’ve to print -1 if temp is NULL.
okk done.
thanks a lot .