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
belongs to collection: Interview C++ coding problems/challenges | Linked list
All Answers
total answers (1)
Pre-requisite:
Algorithm:
Note:
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:
C++ implementation:
Output