Intersection linkedlist problem

what is Y formatted shape linked list ?

I didn’t get about the intersection point but we need to find out the first common element in both link right ?

yes the first common character will be the intersection point


image

Method 3(Using difference of node counts)

  • Get count of the nodes in the first list, let count be c1.
  • Get count of the nodes in the second list, let count be c2.
  • Get the difference of counts d = abs(c1 – c2)
  • Now traverse the bigger list from the first node till d nodes so that from here onwards both the lists have equal no of nodes.
  • Then we can traverse both the lists in parallel till we come across a common node. (Note that getting a common node is done by comparing the address of the nodes)

Below image is a dry run of the above approach:

@chhavibansal got u !!!.
One things when building the two linked list .
I am simple take the two head1 and head2 for each LL but the problem is how to make the next of link to point to intersection Let suppose we have the list
1->2->3->4->5.->null
8->7->3->4->5->null
how the 7 will going to point to 3 because all node as the different memory location so I should like this while iterating if i found the common element in the both list then i will make the prev->next of any one node to point to one head of the common element
1->2->3->4->5.->null
8->7->point the above 3

no need to link it up here becuase here while taking i/p u do not know the intersection point
here u are checking for the values only
when u encounter same value that means that it is the intersection point
but in gfg they have actually taken an intersection point
but this is not possible do it since at the time of input u do not know the intersection
simple compare values

@chhavibansal got it

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.