int intersectPoint(Node* head1, Node* head2)
{
Nodep= head1;
Nodeq = head2;
int c1=0,c2=0,cdiff=0; //c == count
while(p!=NULL) //length of 1st linked list
{ c1++;
p=p->next;
}
while(c2!=NULL) //length of 2nd linked list
{ c2++;
q=q->next;
}
cdiff=max(c1,c2)-min(c1,c2); //diff in number of nodes
p=head1;
q=head2;
if(c1>c2) {
for (int i=0;i<cdiff;i++){ // to make the pointers ponit at equal distance from the common node
if (p == NULL)
return -1;
p=p->next;}
}
if(c2>c1){
for (int i=0;i<cdiff;i++){
if (q == NULL) // null before common node , i.e common node not exixt
return -1;
q=q->next;}
}
while(p!=NULL && q!=NULL){
if(p==q) //compare the nodes instead of the data
return p->data;
p=p->next;
q=q->next;
}
return -1;
// Your Code Here
}