<?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>add two numbers represented by linked lists - Interview Questions</title>
	<atom:link href="https://www.wikitechy.com/interview-questions/tag/add-two-numbers-represented-by-linked-lists/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.wikitechy.com/interview-questions/tag/add-two-numbers-represented-by-linked-lists/</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.1.1</generator>
	<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>
[pastacode lang=&#8221;markdown&#8221; manual=&#8221;Input%3A%0A%20%20%20List1%3A%2020-%3E25-%3E4-%3E30%0A%20%20%20lsit2%3A%20%208-%3E4-%3E2-%3E20%0AOutput%3A%0A%20%20%20Intersection%20List%3A%204-%3E20&#8243; message=&#8221;&#8221; highlight=&#8221;&#8221; provider=&#8221;manual&#8221;/]
<h2 id="sample-code-in-c" class="color-purple" style="text-align: justify;">Sample Code in C:</h2>
[pastacode lang=&#8221;c&#8221; manual=&#8221;%2F%20C%20program%20to%20get%20intersection%20point%20of%20two%20linked%20list%20%20%0A%23include%3Cstdio.h%3E%20%0A%23include%3Cstdlib.h%3E%20%0A%20%20%0A%2F*%20Link%20list%20node%20*%2F%0Astruct%20Node%20%0A%7B%20%0A%20%20int%20data%3B%20%0A%20%20struct%20Node*%20next%3B%20%0A%7D%3B%20%0A%20%20%0A%2F*%20Function%20to%20get%20the%20counts%20of%20node%20in%20a%20linked%20list%20*%2F%0Aint%20getCount(struct%20Node*%20head)%3B%20%0A%20%20%0A%2F*%20function%20to%20get%20the%20intersection%20point%20of%20two%20linked%20%0A%20%20%20lists%20head1%20and%20head2%20where%20head1%20has%20d%20more%20nodes%20than%20%0A%20%20%20head2%20*%2F%0Aint%20_getIntesectionNode(int%20d%2C%20struct%20Node*%20head1%2C%20struct%20Node*%20head2)%3B%20%0A%20%20%0A%2F*%20function%20to%20get%20the%20intersection%20point%20of%20two%20linked%20%0A%20%20%20lists%20head1%20and%20head2%20*%2F%0Aint%20getIntesectionNode(struct%20Node*%20head1%2C%20struct%20Node*%20head2)%20%0A%7B%20%0A%20%20int%20c1%20%3D%20getCount(head1)%3B%20%0A%20%20int%20c2%20%3D%20getCount(head2)%3B%20%0A%20%20int%20d%3B%20%0A%20%20%0A%20%20if(c1%20%3E%20c2)%20%0A%20%20%7B%20%0A%20%20%20%20d%20%3D%20c1%20-%20c2%3B%20%0A%20%20%20%20return%20_getIntesectionNode(d%2C%20head1%2C%20head2)%3B%20%0A%20%20%7D%20%0A%20%20else%0A%20%20%7B%20%0A%20%20%20%20d%20%3D%20c2%20-%20c1%3B%20%0A%20%20%20%20return%20_getIntesectionNode(d%2C%20head2%2C%20head1)%3B%20%0A%20%20%7D%20%0A%7D%20%0A%20%20%0A%2F*%20function%20to%20get%20the%20intersection%20point%20of%20two%20linked%20%0A%20%20%20lists%20head1%20and%20head2%20where%20head1%20has%20d%20more%20nodes%20than%20%0A%20%20%20head2%20*%2F%0Aint%20_getIntesectionNode(int%20d%2C%20struct%20Node*%20head1%2C%20struct%20Node*%20head2)%20%0A%7B%20%0A%20%20int%20i%3B%20%0A%20%20struct%20Node*%20current1%20%3D%20head1%3B%20%0A%20%20struct%20Node*%20current2%20%3D%20head2%3B%20%0A%20%20%0A%20%20for(i%20%3D%200%3B%20i%20%3C%20d%3B%20i%2B%2B)%20%0A%20%20%7B%20%0A%20%20%20%20if(current1%20%3D%3D%20NULL)%20%0A%20%20%20%20%7B%20%20return%20-1%3B%20%7D%20%0A%20%20%20%20current1%20%3D%20current1-%3Enext%3B%20%0A%20%20%7D%20%0A%20%20%0A%20%20while(current1%20!%3D%20%20NULL%20%26%26%20current2%20!%3D%20NULL)%20%0A%20%20%7B%20%0A%20%20%20%20if(current1%20%3D%3D%20current2)%20%0A%20%20%20%20%20%20return%20current1-%3Edata%3B%20%0A%20%20%20%20current1%3D%20current1-%3Enext%3B%20%0A%20%20%20%20current2%3D%20current2-%3Enext%3B%20%0A%20%20%7D%20%0A%20%20%0A%20%20return%20-1%3B%20%0A%7D%20%0A%20%20%0A%2F*%20Takes%20head%20pointer%20of%20the%20linked%20list%20and%20%0A%20%20%20returns%20the%20count%20of%20nodes%20in%20the%20list%20*%2F%0Aint%20getCount(struct%20Node*%20head)%20%0A%7B%20%0A%20%20struct%20Node*%20current%20%3D%20head%3B%20%0A%20%20int%20count%20%3D%200%3B%20%0A%20%20%0A%20%20while%20(current%20!%3D%20NULL)%20%0A%20%20%7B%20%0A%20%20%20%20count%2B%2B%3B%20%0A%20%20%20%20current%20%3D%20current-%3Enext%3B%20%0A%20%20%7D%20%0A%20%20%0A%20%20return%20count%3B%20%0A%7D%20%0A%20%20%0A%2F*%20IGNORE%20THE%20BELOW%20LINES%20OF%20CODE.%20THESE%20LINES%20%0A%20%20%20ARE%20JUST%20TO%20QUICKLY%20TEST%20THE%20ABOVE%20FUNCTION%20*%2F%0Aint%20main()%20%0A%7B%20%0A%20%20%2F*%20%0A%20%20%20%20Create%20two%20linked%20lists%20%0A%20%20%0A%20%20%20%201st%203-%3E6-%3E9-%3E15-%3E30%20%0A%20%20%20%202nd%2010-%3E15-%3E30%20%0A%20%20%0A%20%20%20%2015%20is%20the%20intersection%20point%20%0A%20%20*%2F%0A%20%20%0A%20%20struct%20Node*%20newNode%3B%20%0A%20%20struct%20Node*%20head1%20%3D%20%0A%20%20%20%20%20%20%20%20%20%20%20%20(struct%20Node*)%20malloc(sizeof(struct%20Node))%3B%20%0A%20%20head1-%3Edata%20%20%3D%2010%3B%20%0A%20%20%0A%20%20struct%20Node*%20head2%20%3D%20%0A%20%20%20%20%20%20%20%20%20%20%20%20(struct%20Node*)%20malloc(sizeof(struct%20Node))%3B%20%0A%20%20head2-%3Edata%20%20%3D%203%3B%20%0A%20%20%0A%20%20newNode%20%3D%20(struct%20Node*)%20malloc%20(sizeof(struct%20Node))%3B%20%0A%20%20newNode-%3Edata%20%3D%206%3B%20%0A%20%20head2-%3Enext%20%3D%20newNode%3B%20%0A%20%20%0A%20%20newNode%20%3D%20(struct%20Node*)%20malloc%20(sizeof(struct%20Node))%3B%20%0A%20%20newNode-%3Edata%20%3D%209%3B%20%0A%20%20head2-%3Enext-%3Enext%20%3D%20newNode%3B%20%0A%20%20%0A%20%20newNode%20%3D%20(struct%20Node*)%20malloc%20(sizeof(struct%20Node))%3B%20%0A%20%20newNode-%3Edata%20%3D%2015%3B%20%0A%20%20head1-%3Enext%20%3D%20newNode%3B%20%0A%20%20head2-%3Enext-%3Enext-%3Enext%20%20%3D%20newNode%3B%20%0A%20%20%0A%20%20newNode%20%3D%20(struct%20Node*)%20malloc%20(sizeof(struct%20Node))%3B%20%0A%20%20newNode-%3Edata%20%3D%2030%3B%20%0A%20%20head1-%3Enext-%3Enext%3D%20newNode%3B%20%0A%20%20%0A%20%20head1-%3Enext-%3Enext-%3Enext%20%3D%20NULL%3B%20%0A%20%20%0A%20%20printf(%22%5Cn%20The%20node%20of%20intersection%20is%20%25d%20%5Cn%22%2C%20%0A%20%20%20%20%20%20%20%20%20%20getIntesectionNode(head1%2C%20head2))%3B%20%0A%20%20%0A%20%20getchar()%3B%20%0A%7D%20&#8243; message=&#8221;&#8221; highlight=&#8221;&#8221; provider=&#8221;manual&#8221;/]
<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>
