Intersection point two linked lists

Run error in testcase2. Other 3 testcases are correct. please help.

Hi @vivek21,
The way you are adding nodes to your linked list 2 is wrong .Here is a quick fix.check for comments.

Not got what you are trying to say.

The way you are forming your second linked list was a bit wrong. For a test case there was null pointer that means your linked list was not forming.

When node is null, according to my program its not found in first list. therefore if node is null, we need to add new node to list2.

Whats the problem in that?

You search whether the node is not in list1. If the first element of list2 is found in list1 then in your code it will increment the tail of list2. But for the first element tail element is not defined yet. Therefore run error.

1 Like