Intersection Point of Two Linked Lists

My code is not working for one test case, can someone help tell the mistake?

int intersection_point2(node* head1,node* head2) { node* curr1=head1; node* curr2=head2; int l1=length(curr1); int l2=length(curr2); if(l1>l2) { int diff=l1-l2; for(int i=0;i<diff;i++) { if(curr1==NULL) return -1; curr1=curr1->next; } } else { int diff=l2-l1; for(int i=0;i<diff;i++) { if(curr2==NULL) return -1; curr2=curr2->next; } } while(curr1!=NULL && curr2!=NULL) { if(curr1->data < curr2->data) { curr1=curr1->next; } else if( curr1->data > curr2->data) { curr2=curr2->next; } else { return curr1->data; } } return -1; }

ratik save ur code to https://ide.codingblocks.com and then share the link here

Hey Ratik,
As you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.