Why it is giving run error plz check

i am unable to understand this

Hey @mohitsingh see if this is 2 merged linked list and bigger linked list has length 6 and shorter 5 then first find the difference which in this case is 1, the linked list which is bigger in size . In that linked list travel to that much node , here you will reach at 10th node.
Now one pointer is at 10th node and another is at 5th node, now increment node by node and return that node which proves ptr1==ptr2

Node *intersectionOfTwoLinkedLists(Node *l1, Node *l2) { Node *temp1=l1; Node *temp2=l2; while(temp1!=NULL && temp2!=NULL && temp1->data!=temp2->data){ cout<data<<endl; temp1=temp1->next; temp2=temp2->next; } return temp1; /Code here/ }

i got your this code, it will give you TLE only. Use the approach i have mentioned above.

why it is giving tle

Cause of it’s bad time complexity. Try to do it in O(n)
These are all the approach with time complexity mentioned in the editorial. Choose as per your convenience

my approach is also the O(n) i am not understanding the two approaches have exactly the same complexity

in submission it is giving run error and wrong answer also i dont understand why

Tell me the approach you are framing. For which you are querying.

If you are using 2 pointer approach then do it like this


It’s not equal linked list, you will get TLE when any of the pointer of the assigned linked list reaches to tail.

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.