Interview Questions

Whats a Linked List ? Given Two linked list forming a Y shaped linked list ......

Software QA/Tests Interview Questions from Microsoft


(Continued from previous question...)

Whats a Linked List ? Given Two linked list forming a Y shaped linked list ......

Q:
Microsoft Interview Question for SDE in tests
Whats a Linked List ? Given Two linked list forming a Y shaped linked list . Find the intersecting node...where one list has more nodes than the other ? Runtime analysis etc etc .


A:
In the case of sorted linked list
1.Make two pointers pointing to each head ptr1,ptr2.
2.if(ptr1->data==ptr2->data) two pointers are pointing same node return the current node
3.else if ptr1->data>ptr2->data then increment ptr1 to next node
4.else increment ptr2 to next node
5.goto second step

if linked list is not sorted one..
1.make two pointers pointing to each head.
2.find number of nodes in each pointers.
3.find the difference of each count
4.move the longest list pointer for above difference from the head
5.the move the each pointer,return the meeting point.

(Continued on next question...)

Other Interview Questions