Interview Questions

Write a code to find if two linked list intersect

Software QA/Tests Interview Questions from Microsoft


Write a code to find if two linked list intersect

Q:
Software Engineer in Tests about Algorithm: Write a code to find if two linked list intersect

A:
Two ways : One by counting the length of the two linked list and then advancing the the bigger linked list by the difference in length and then advancing both the pointers simulataneously to check if they intersect.

A method to join the last node of a linked list to the first node and checking if a cycle exist.

(Continued on next question...)

Other Interview Questions