Y formed linked list

how to make the Y shape linked list

Hey
You’ve to create both linked lists simply by using the data given for creation, then you’ve to find their intersection, the creation method is not different from normal linked list creation

@mahimahans111
so how this will pointed to the intersection point because at some point the linked list intersection and after that all the elements will same
if i create like that
1->2->3->4-X
10->2->3->4->x
then for sure then head1, head2 pointer points do the different node all the times even when the both the list has some common elements

For calculating the intersection point, the basic approach that you could follow is firstly to calculate the no of elements which are present in both linked list and then calculating the difference and making the pointer go to that position uptill there is difference, and making your pointer of a and b move uptil there data is different, and if at any point (a->data == b->data), that point will be treated as intersection point.

So basically to find the intersection point, you need to compare data of both, so it’ll work even when you create both the linked lists separately.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

@mahimahans111 got solved it thanks