Reaches time out. efficiency is O(m+n)

Node *intersectionOfTwoLinkedLists(Node l1, Node l2)
{
int len1=0,len2=0;
Node
t1 = l1;
Node
t2 = l2;
while(l1!=NULL){
len1++;
l1= l1->next;
}
while(l2!=NULL){
len2++;
l2= l2->next;

}
int diff = 0;
if(len1>len2){
    diff = len1-len2;
    for(int i=0;i<diff;i++)
        l1 = l1->next;
}
else if(len1<len2){
    diff = len2-len1;
    for(int i=0;i<diff;i++)
        l1 = l1->next;
}
// else{
while(l1!=l2){
    l1 = l1->next;
    l2 = l2->next;
}
return l1;
/

hi @anmolsri1_27cc712632507b5a heres the updated code https://ide.codingblocks.com/s/659885 ive commented

still getting error as : runguard: warning: timelimit exceeded (wall time): aborting command runguard: warning: command terminated with signal 15

@anmolsri1_27cc712632507b5a idk y its showing error just submit, its passing all test case

LOL.
Was showing error on compile and test.
Passed on submit.

1 Like

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.