i used a different approach than the one in the video . 3 of my test cases are correct and one fails , can you pls tell me whats missing in my code
I used a different approach for solving intersection point two linked list
Hello @Anchal,
Your code is failing for the test cases like:
Example 1:
10
1 2 3 4 5 6 7 8 9 10
3
12 11 10
Expected Output:
10
Your Output:
-1
Example 2:
3
1 3 4
3
6 3 4
Expected Output:
3
Your Output:
-1
Reason:
The approach you have used will work only if the two linked list are sorted.
In example 2:
As 6 (i.e. the first element of the second list) is greater than all the elements of the first linked list.
So, while loop will iterate the entire first list and then terminate.
i.e. will execute only the following segment of code:
if(head1->datadata)
{
head1=head1->next;
}
Hope, this would help.
Give a like if you are satisfied.