Interview Questions

259. There are two linked lists A and B. Find if they both intersect.....

Microsoft Interview Questions and Answers


(Continued from previous question...)

259. There are two linked lists A and B. Find if they both intersect.....

Question:
There are two linked lists A and B. Find if they both intersect. If yes, then also find their point of intersection.


maybe an answer:


node *temp, *prev;
temp = list_a.head;
while(temp != NULL)
{
stack_a.push(temp);
temp = temp->next;
}
temp = list_b.head;
while(temp != NULL)
{
stack_b.push(temp)
temp = temp->next;
}
prev = NULL;
temp = stack_a.pop();
while(temp == stack_b.pop())
{
prev = temp;
}
return(prev);

(Continued on next question...)

Other Interview Questions