NVIDIA Interview Question
Software Engineer / Developerstraverse the lists from head to tail and put the node pointers of each lists in stacks
ListA -> StackA
ListB -> StackB
(1) if they intersect, then the top element of both stacks will be same
(2) if (1) is true, keep popping up till the elements of stack have same value (node addresses) the last popped will be the intersection point
Eg- 100 is the last matched and popped node in the following
2--3--4--5--6--7--
\--- 100--200--300
20--30--40--50-- /
stackA 300--200--100--7--6-- ...--2
stackB 300--200--100--50--40--30--20
geeksforgeeks.org/?p=2405
- Rahul D March 20, 2011