Interview Questions

261. Remove intersections of two single linked list and make one linked list.....

Microsoft Interview Questions and Answers


(Continued from previous question...)

261. Remove intersections of two single linked list and make one linked list.....

Question:
Remove intersections of two single linked list and make one linked list. operations should be recursive.


maybe an answer:


Pseudocode:
RemoveIntersection(*list 1, *list 2, **list3)
{
continue this loop till either of the list becomes NULL and after that simply append the nodes of the remaining list (non-empty list) to the new list (list3)

if(list1->value == list2->value)
{
newNode = list1->value
list1 = lis1->next
list2 = list2->next
}
else if(list1->value < list2->value)
{
newNode = list1->value
list1 = list1->next
}
else
{
newNode = list2->value
list2 = list2->next
}

if(*list3 == NULL)
*list3 = newNode;
else
*list3->next = newNode
}

(Continued on next question...)

Other Interview Questions