<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>find the merge point of two linked lists in c++ - Wikitechy</title>
	<atom:link href="https://www.wikitechy.com/interview-questions/tag/find-the-merge-point-of-two-linked-lists-in-c/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.wikitechy.com/interview-questions/tag/find-the-merge-point-of-two-linked-lists-in-c/</link>
	<description>Interview Questions</description>
	<lastBuildDate>Mon, 13 Sep 2021 06:45:11 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.wikitechy.com/interview-questions/wp-content/uploads/2025/10/cropped-wikitechy-icon-32x32.png</url>
	<title>find the merge point of two linked lists in c++ - Wikitechy</title>
	<link>https://www.wikitechy.com/interview-questions/tag/find-the-merge-point-of-two-linked-lists-in-c/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Write a function to get the intersection point of two Linked Lists</title>
		<link>https://www.wikitechy.com/interview-questions/data-structure/write-a-function-to-get-the-intersection-point-of-two-linked-lists/</link>
					<comments>https://www.wikitechy.com/interview-questions/data-structure/write-a-function-to-get-the-intersection-point-of-two-linked-lists/#respond</comments>
		
		<dc:creator><![CDATA[Editor]]></dc:creator>
		<pubDate>Tue, 13 Jul 2021 17:04:15 +0000</pubDate>
				<category><![CDATA[Data Structure]]></category>
		<category><![CDATA[Accenture interview questions and answers]]></category>
		<category><![CDATA[add two numbers represented by linked lists]]></category>
		<category><![CDATA[Altimetrik India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[Applied Materials interview questions and answers]]></category>
		<category><![CDATA[Bharti Airtel interview questions and answers]]></category>
		<category><![CDATA[BMC Software interview questions and answers]]></category>
		<category><![CDATA[Capgemini interview questions and answers]]></category>
		<category><![CDATA[CASTING NETWORKS INDIA PVT LIMITED interview questions and answers]]></category>
		<category><![CDATA[CGI Group Inc interview questions and answers]]></category>
		<category><![CDATA[Chetu interview questions and answers]]></category>
		<category><![CDATA[Ciena Corporation interview questions and answers]]></category>
		<category><![CDATA[Collabera Te interview questions and answers]]></category>
		<category><![CDATA[compro technologies interview questions and answers]]></category>
		<category><![CDATA[Dell International Services India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[detect loop in linked list]]></category>
		<category><![CDATA[find the merge point of two linked lists in c++]]></category>
		<category><![CDATA[find the merge point of two linked lists in data structure]]></category>
		<category><![CDATA[Flipkart interview questions and answers]]></category>
		<category><![CDATA[Genpact interview questions and answers]]></category>
		<category><![CDATA[Globallogic India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[how to move a node in a linked list java]]></category>
		<category><![CDATA[IBM interview questions and answers]]></category>
		<category><![CDATA[Indecomm Global Services interview questions and answers]]></category>
		<category><![CDATA[intersection of two linked lists]]></category>
		<category><![CDATA[intersection of two linked lists c++]]></category>
		<category><![CDATA[intersection of two linked lists in c]]></category>
		<category><![CDATA[intersection of two lists java]]></category>
		<category><![CDATA[intersection point in y shapped linked lists]]></category>
		<category><![CDATA[list intersection c++]]></category>
		<category><![CDATA[merge sort for linked list]]></category>
		<category><![CDATA[Mphasis interview questions and answers]]></category>
		<category><![CDATA[NetApp interview questions and answers]]></category>
		<category><![CDATA[Oracle Corporation interview questions and answers]]></category>
		<category><![CDATA[pairwise swap of a linked list]]></category>
		<category><![CDATA[SAP Labs India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[Sapient Consulting Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[swap nodes doubly linked list c++]]></category>
		<category><![CDATA[Tech Mahindra interview questions and answers]]></category>
		<category><![CDATA[Tracxn Technologies Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[union and intersection of two linked lists in c++]]></category>
		<category><![CDATA[union and intersection of two linked lists in python]]></category>
		<category><![CDATA[union and intersection of two linked lists using c++]]></category>
		<category><![CDATA[union find linked list java]]></category>
		<category><![CDATA[union of two linked lists c++]]></category>
		<category><![CDATA[UnitedHealth Group interview questions and answers]]></category>
		<category><![CDATA[Wipro Infotech interview questions and answers]]></category>
		<category><![CDATA[WM Global Technology Services India Pvt.Ltd Limited (WMGTS) interview questions and answers]]></category>
		<category><![CDATA[Xoriant Solutions Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[Yodlee Infotech Pvt Ltd interview questions and answers]]></category>
		<guid isPermaLink="false">https://www.wikitechy.com/interview-questions/?p=501</guid>

					<description><![CDATA[Answer : Intersection point means end of one linked list is linked..]]></description>
										<content:encoded><![CDATA[<div class="TextHeading">
<div class="hddn">
<h2 id="write-a-function-to-get-the-intersection-point-of-two-linked-lists" class="color-pink" style="text-align: justify;">Write a function to get the intersection point of two Linked Lists</h2>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li>Intersection point means end of one <a href="https://www.wikitechy.com/tutorials/csharp/csharp-linked-list" target="_blank" rel="noopener">linked list</a> is linked with some node in another linked list.</li>
</ul>
</div>
</div>
<div class="ImageContent" style="text-align: justify;">
<div class="hddn"><img decoding="async" class="img-responsive center-block aligncenter" src="https://cdn.wikitechy.com/interview-questions/data-structure/intersection-linked-list.png" alt=" data- linked-list" /></div>
</div>
<p style="text-align: justify;">Given two Linked Lists, create intersection lists that contain intersection of the elements present in the given lists.</p>
<div class="TextHeading">
<div class="hddn">
<h2 id="example" class="color-pink" style="text-align: justify;">Example</h2>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-markdown code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-markdown code-embed-code">Input:<br/>   List1: 20-&gt;25-&gt;4-&gt;30<br/>   lsit2:  8-&gt;4-&gt;2-&gt;20<br/>Output:<br/>   Intersection List: 4-&gt;20</code></pre> </div>
<h2 id="sample-code-in-c" class="color-purple" style="text-align: justify;">Sample Code in C:</h2>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-c code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-c code-embed-code">/ C program to get intersection point of two linked list  <br/>#include&lt;stdio.h&gt; <br/>#include&lt;stdlib.h&gt; <br/>  <br/>/* Link list node */<br/>struct Node <br/>{ <br/>  int data; <br/>  struct Node* next; <br/>}; <br/>  <br/>/* Function to get the counts of node in a linked list */<br/>int getCount(struct Node* head); <br/>  <br/>/* function to get the intersection point of two linked <br/>   lists head1 and head2 where head1 has d more nodes than <br/>   head2 */<br/>int _getIntesectionNode(int d, struct Node* head1, struct Node* head2); <br/>  <br/>/* function to get the intersection point of two linked <br/>   lists head1 and head2 */<br/>int getIntesectionNode(struct Node* head1, struct Node* head2) <br/>{ <br/>  int c1 = getCount(head1); <br/>  int c2 = getCount(head2); <br/>  int d; <br/>  <br/>  if(c1 &gt; c2) <br/>  { <br/>    d = c1 - c2; <br/>    return _getIntesectionNode(d, head1, head2); <br/>  } <br/>  else<br/>  { <br/>    d = c2 - c1; <br/>    return _getIntesectionNode(d, head2, head1); <br/>  } <br/>} <br/>  <br/>/* function to get the intersection point of two linked <br/>   lists head1 and head2 where head1 has d more nodes than <br/>   head2 */<br/>int _getIntesectionNode(int d, struct Node* head1, struct Node* head2) <br/>{ <br/>  int i; <br/>  struct Node* current1 = head1; <br/>  struct Node* current2 = head2; <br/>  <br/>  for(i = 0; i &lt; d; i++) <br/>  { <br/>    if(current1 == NULL) <br/>    {  return -1; } <br/>    current1 = current1-&gt;next; <br/>  } <br/>  <br/>  while(current1 !=  NULL &amp;&amp; current2 != NULL) <br/>  { <br/>    if(current1 == current2) <br/>      return current1-&gt;data; <br/>    current1= current1-&gt;next; <br/>    current2= current2-&gt;next; <br/>  } <br/>  <br/>  return -1; <br/>} <br/>  <br/>/* Takes head pointer of the linked list and <br/>   returns the count of nodes in the list */<br/>int getCount(struct Node* head) <br/>{ <br/>  struct Node* current = head; <br/>  int count = 0; <br/>  <br/>  while (current != NULL) <br/>  { <br/>    count++; <br/>    current = current-&gt;next; <br/>  } <br/>  <br/>  return count; <br/>} <br/>  <br/>/* IGNORE THE BELOW LINES OF CODE. THESE LINES <br/>   ARE JUST TO QUICKLY TEST THE ABOVE FUNCTION */<br/>int main() <br/>{ <br/>  /* <br/>    Create two linked lists <br/>  <br/>    1st 3-&gt;6-&gt;9-&gt;15-&gt;30 <br/>    2nd 10-&gt;15-&gt;30 <br/>  <br/>    15 is the intersection point <br/>  */<br/>  <br/>  struct Node* newNode; <br/>  struct Node* head1 = <br/>            (struct Node*) malloc(sizeof(struct Node)); <br/>  head1-&gt;data  = 10; <br/>  <br/>  struct Node* head2 = <br/>            (struct Node*) malloc(sizeof(struct Node)); <br/>  head2-&gt;data  = 3; <br/>  <br/>  newNode = (struct Node*) malloc (sizeof(struct Node)); <br/>  newNode-&gt;data = 6; <br/>  head2-&gt;next = newNode; <br/>  <br/>  newNode = (struct Node*) malloc (sizeof(struct Node)); <br/>  newNode-&gt;data = 9; <br/>  head2-&gt;next-&gt;next = newNode; <br/>  <br/>  newNode = (struct Node*) malloc (sizeof(struct Node)); <br/>  newNode-&gt;data = 15; <br/>  head1-&gt;next = newNode; <br/>  head2-&gt;next-&gt;next-&gt;next  = newNode; <br/>  <br/>  newNode = (struct Node*) malloc (sizeof(struct Node)); <br/>  newNode-&gt;data = 30; <br/>  head1-&gt;next-&gt;next= newNode; <br/>  <br/>  head1-&gt;next-&gt;next-&gt;next = NULL; <br/>  <br/>  printf(&quot;\n The node of intersection is %d \n&quot;, <br/>          getIntesectionNode(head1, head2)); <br/>  <br/>  getchar(); <br/>} </code></pre> </div>
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="code-explanation" class="color-purple">Code Explanation :</h2>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li>Get count of the nodes in the first list, let count be c1.</li>
<li>Get count of the nodes in the second list, let count be c2.</li>
<li>Get the difference of counts d = abs (c1 &#8211; c2)</li>
<li>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.</li>
<li>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)</li>
</ul>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<p align="justify">Time Complexity: O(m+n)<br />
Auxiliary Space: O(1)</p>
</div>
</div>
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="output" class="color-blue">Output :</h2>
</div>
</div>
<div class="Output">
<div class="hddn">
<figure class="highlight" style="text-align: justify;">
<pre><code class="hljs javascript" data-lang=""><span class="nt">The node <span class="hljs-keyword">of</span> intersection is <span class="hljs-number">15</span></span></code></pre>
</figure>
</div>
</div>
</div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.wikitechy.com/interview-questions/data-structure/write-a-function-to-get-the-intersection-point-of-two-linked-lists/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
