Intersection Point in Y-Shaped Linked List
There are two singly linked lists where end nodes of one linked list got linked into the second list, forming aY (or T ) shaped list. Write a program to get the point where two linked lists got merged.
1 → 2 → 3 → 6 ← 4 ← 5 ↓ 8 ↓ NULL
head1 is 1 and head2 is 5, both have a common merged tail portion which is 6 -> 8 -> NULL. So the intersection point is 6.
The nodes (pointer to nodes) are to be inserted into the set, not the node data. Let's say for an input example both heads have the same input data (for example say 1), but nodes are actually different (no intersection there). But if we maintain the set with node data, then that will return the 1, which is the wrong answer.
For the above example, answer will be 1 if we start inserting node->data to the set instead of node. But the actual answer is 6.
Explanation with example: