How to take input so that only one linked list form

INTERSECTION POINT TWO LINKED LISTS
There are two linked lists. Due to some programming error, the end node of one of the linked list got linked into the second list, forming an inverted Y shaped list. Now it’s your job to find the point(Node) at which the two linked lists are intersecting.

hey @divyamsaxena123, if a linked list hai 5 elements that call insertion at tail function 5 times. Remember that one node has same data in 2 linked lists, they are completely 2 different linked list

if these are two different linked list then address of node which contain same data is also differemt

then how can we solve in O(m+n)

pls provide code snippet of how to take input

hey @divyamsaxena123, address is not same, only data is same

here is the code snippet you want:

void insertAtTail(node* &head,int data)
{
if(head==NULL)
{
head=new node(data);
return;
}
node* temp=head;
while(temp->next!=NULL)
{
temp=temp->next;
}
temp->next=new node(data);
}

void build(node* &head,int N)
{
int data;
while(N–)
{
cin>>data;
insertAtTail(head,data);
}
}

int main()
{
node* head1=NULL;
node* head2=NULL;
int N1,N2;
cin>>N1;
build(head1,N1);
cin>>N2;
build(head2,N2);
}

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.