PROBLEM:
Intersection point two linked lists
There are two linked lists. Due to some programming error, the end node of one of the linked list got linked into the second list, forming an inverted Y shaped list. Now it’s your job to find the point(Node) at which the two linked lists are intersecting.
MY APPROACH:
- join the head of one linked list with the tail of another
- check if cycle exists, IF NOT join tail of first list to head of another
- check if cycle exists, IF NOT return (no intersection point)
- Create the cycle
- Find starting point of cycle using a fast-moving and slow-moving pointer
- this point is intersection
HOW TO IMPLEMENT THIS? if it is right
What other approaches to try? Should we simply compare when linked lists start getting same values of nodes?