Interview Questions

Given 2 sorted linked lists - merge them. Make sure you don't have duplicates in the merged list. .......

Software QA/Tests Interview Questions from Microsoft


(Continued from previous question...)

Given 2 sorted linked lists - merge them. Make sure you don't have duplicates in the merged list. .......

Q:
Microsoft Interview Question for SDE in tests about Algorithm
Given 2 sorted linked lists - merge them. Make sure you don't have duplicates in the merged list. The input lists could have duplicates within them or across the 2 lists.

node *merge(node *p,node *q)
{
if(p==NULL) return q;
if(q==NULL) return p;
if(p->data==q->data)
{
p->next=merge(p->next,q->next);
delete q;
return p;
}
if(p->data>q->data)
{
q->next=merge(p,q->next);
return q;
}
p->next=merge(p->next,q);
return p;
}

(Continued on next question...)

Other Interview Questions