<?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>samsung interview questions and answers - Interview Questions</title>
	<atom:link href="https://www.wikitechy.com/interview-questions/tag/samsung-interview-questions-and-answers/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.wikitechy.com/interview-questions/tag/samsung-interview-questions-and-answers/</link>
	<description>Interview Questions</description>
	<lastBuildDate>Thu, 16 Sep 2021 12:32:43 +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>How to Count number of bits to be flipped to convert A to B ?</title>
		<link>https://www.wikitechy.com/interview-questions/data-structure/how-to-count-number-of-bits-to-be-flipped-to-convert-a-to-b/</link>
					<comments>https://www.wikitechy.com/interview-questions/data-structure/how-to-count-number-of-bits-to-be-flipped-to-convert-a-to-b/#respond</comments>
		
		<dc:creator><![CDATA[Editor]]></dc:creator>
		<pubDate>Tue, 13 Jul 2021 17:48:41 +0000</pubDate>
				<category><![CDATA[Data Structure]]></category>
		<category><![CDATA[Accenture interview questions and answers]]></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[bit flipping game code]]></category>
		<category><![CDATA[bit manipulation in c]]></category>
		<category><![CDATA[BMC Software interview questions and answers]]></category>
		<category><![CDATA[brian kernighan’s algorithm]]></category>
		<category><![CDATA[c program to count number of ones and zeros]]></category>
		<category><![CDATA[c program to toggle a bit]]></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[count number of 1s in a binary number java]]></category>
		<category><![CDATA[count set bits]]></category>
		<category><![CDATA[count set bits in a number c++]]></category>
		<category><![CDATA[count total set bits in all numbers from 1 to n]]></category>
		<category><![CDATA[counting bits]]></category>
		<category><![CDATA[counting bits set by lookup table]]></category>
		<category><![CDATA[Dell International Services India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[flip all bits in c]]></category>
		<category><![CDATA[flip bits]]></category>
		<category><![CDATA[Flipkart interview questions and answers]]></category>
		<category><![CDATA[flipped mountain code in c]]></category>
		<category><![CDATA[flipped mountain code in java]]></category>
		<category><![CDATA[flipped mountain in c]]></category>
		<category><![CDATA[flipped mountain pattern program in java]]></category>
		<category><![CDATA[flipped mountain program in c]]></category>
		<category><![CDATA[flipped mountain program in java]]></category>
		<category><![CDATA[flipped mountain program in python]]></category>
		<category><![CDATA[flipping bits in c]]></category>
		<category><![CDATA[flipping bits in java]]></category>
		<category><![CDATA[flipping bits program in c]]></category>
		<category><![CDATA[flipping bits solution]]></category>
		<category><![CDATA[flipping bits solution in c]]></category>
		<category><![CDATA[Genpact interview questions and answers]]></category>
		<category><![CDATA[Globallogic India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[how to count number of 1's in binary representation in c]]></category>
		<category><![CDATA[IBM interview questions and answers]]></category>
		<category><![CDATA[Indecomm Global Services interview questions and answers]]></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[reverse bytes in c]]></category>
		<category><![CDATA[samsung interview questions and answers]]></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[Tech Mahindra interview questions and answers]]></category>
		<category><![CDATA[toggle all bits in c]]></category>
		<category><![CDATA[Tracxn Technologies Pvt Ltd interview questions and answers]]></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=513</guid>

					<description><![CDATA[Answer : Write the program to count number of bits needed to be flipped...]]></description>
										<content:encoded><![CDATA[<div class="TextHeading">
<div class="hddn">
<h2 id="how-to-count-number-of-bits-to-be-flipped-to-convert-a-to-b" class="color-pink" style="text-align: justify;">How to Count number of bits to be flipped to convert A to B ?</h2>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li>Write the program to count number of bits needed to be flipped to convert ‘a’ to ‘b’. For Example given two numbers a = 6 and b = 12; then the output is 2
<ul>
<li><a href="https://www.wikitechy.com/technology/check-binary-representation-number-palindrome/" target="_blank" rel="noopener">Binary representation</a> of a is 00000<b>11</b>0</li>
<li>Binary representation of b is 00001100</li>
<li>We need to flip highlighted two bits in a</li>
<li>To make it b.</li>
</ul>
</li>
</ul>
</div>
</div>
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="explanation" class="color-purple">Explanation</h2>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li>Calculate XOR of A and B.</li>
</ul>
</div>
</div>
<div class="Output" style="text-align: justify;">
<div class="hddn">
<figure class="highlight">
<pre><code class="hljs" data-lang=""><span class="nt">a_xor_b = A ^ B</span></code></pre>
</figure>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li>Count the set bits in the above Calculated XOR result.</li>
</ul>
</div>
</div>
<div class="Output" style="text-align: justify;">
<div class="hddn">
<figure class="highlight">
<pre><code class="hljs scss" data-lang=""><span class="nt"><span class="hljs-function">CountSetBits</span>(a_xor_b)</span></code></pre>
</figure>
</div>
</div>
<div class="TextHeading">
<div class="hddn">
<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%20Count%20number%20of%20bits%20to%20be%20%0A%2F%2F%20flipped%20to%20convert%20A%20into%20B%20%0Ausing%20System%3B%20%0A%0Apublic%20class%20Count%20%7B%20%0A%09%0A%09%2F%2F%20Function%20that%20count%20set%20bits%20%0A%09public%20static%20int%20countSetBits(int%20n)%20%0A%09%7B%20%0A%09%09int%20count%20%3D%200%3B%20%0A%09%09while%20(n%20!%3D%200)%20%7B%20%0A%09%09%09count%20%2B%3D%20n%20%26%201%3B%20%0A%09%09%09n%20%3E%3E%3D%201%3B%20%0A%09%09%7D%20%0A%09%09return%20count%3B%20%0A%09%7D%20%0A%0A%09%2F%2F%20Function%20that%20return%20%0A%09%2F%2F%20count%20of%20flipped%20number%20%0A%09public%20static%20int%20FlippedCount(int%20a%2C%20int%20b)%20%0A%09%7B%20%0A%09%2F%2F%20Return%20count%20of%20set%20%0A%09%2F%2F%20bits%20in%20a%20XOR%20b%20%0A%09%09return%20countSetBits(a%20%5E%20b)%3B%20%0A%09%7D%20%0A%09%0A%09%2F%2F%20Driver%20code%20%0A%09public%20static%20void%20Main()%20%0A%09%7B%20%0A%09%09int%20a%20%3D%2017%3B%20%0A%09%09int%20b%20%3D%2055%3B%20%0A%09%09Console.WriteLine(FlippedCount(a%2C%20b))%3B%20%0A%09%7D%20%0A%7D%20%0A%0A%2F%2F%20This%20code%20is%20contributed%20by%20vt_m.%20&#8243; message=&#8221;&#8221; highlight=&#8221;&#8221; provider=&#8221;manual&#8221;/]
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="output" class="color-purple">Output</h2>
</div>
</div>
<div class="Output">
<div class="hddn">
<figure class="highlight" style="text-align: justify;">
<pre><code class="hljs" data-lang=""><span class="nt">3</span></code></pre>
</figure>
</div>
</div>
</div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.wikitechy.com/interview-questions/data-structure/how-to-count-number-of-bits-to-be-flipped-to-convert-a-to-b/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>What are the Minimum Initial Points to Reach Destination ?</title>
		<link>https://www.wikitechy.com/interview-questions/data-structure/what-are-the-minimum-initial-points-to-reach-destination/</link>
					<comments>https://www.wikitechy.com/interview-questions/data-structure/what-are-the-minimum-initial-points-to-reach-destination/#respond</comments>
		
		<dc:creator><![CDATA[Editor]]></dc:creator>
		<pubDate>Tue, 13 Jul 2021 17:44:33 +0000</pubDate>
				<category><![CDATA[Data Structure]]></category>
		<category><![CDATA[Accenture interview questions and answers]]></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[bottom and up moves allowed]]></category>
		<category><![CDATA[bottom moves allowed]]></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[Dell International Services India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[find minimum moves to reach target on an infinite line]]></category>
		<category><![CDATA[find shortest path in 2d array in c]]></category>
		<category><![CDATA[find shortest path in matrix python]]></category>
		<category><![CDATA[find the minimum number of moves needed to move from one cell of matrix to another]]></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[IBM interview questions and answers]]></category>
		<category><![CDATA[Indecomm Global Services interview questions and answers]]></category>
		<category><![CDATA[maximum cost path dynamic programm]]></category>
		<category><![CDATA[min cost flow]]></category>
		<category><![CDATA[minimum cost path]]></category>
		<category><![CDATA[minimum cost path dijkstra]]></category>
		<category><![CDATA[minimum cost path graph]]></category>
		<category><![CDATA[minimum cost path matrix java]]></category>
		<category><![CDATA[minimum cost path with left]]></category>
		<category><![CDATA[minimum cost path with right]]></category>
		<category><![CDATA[minimum number of jumps to reach end in java]]></category>
		<category><![CDATA[minimum number of jumps to reach end python]]></category>
		<category><![CDATA[minimum number of steps to reach a given number]]></category>
		<category><![CDATA[minimum steps to one dynamic programming]]></category>
		<category><![CDATA[minimum steps to reach a destination java]]></category>
		<category><![CDATA[minimum sum descent dynamic programming]]></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[samsung interview questions and answers]]></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[shortest distance between two cells in a matrix or grid java]]></category>
		<category><![CDATA[shortest path between two points in a grid java]]></category>
		<category><![CDATA[shortest path from source to destination in matrix java]]></category>
		<category><![CDATA[shortest path in grid with obstacles]]></category>
		<category><![CDATA[shortest path in grid with obstacles python]]></category>
		<category><![CDATA[shortest path in matrix]]></category>
		<category><![CDATA[Tech Mahindra interview questions and answers]]></category>
		<category><![CDATA[Tracxn Technologies Pvt Ltd interview questions and answers]]></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=511</guid>

					<description><![CDATA[Answer : To begin from the upper left corner of a given framework...]]></description>
										<content:encoded><![CDATA[<div>
<div class="hddn">
<h2 id="what-are-the-minimum-initial-points-to-reach-destination" class="color-pink" style="text-align: justify;">What are the Minimum Initial Points to Reach Destination ?</h2>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li>To begin from the upper left corner of a given framework, one needs to achieve the base right corner.</li>
<li>Every cell in the grid contains a number, the number may positive or negative.</li>
<li>We can move across a cell only if we have positive points ( &gt; 0 ). Whenever we pass through a cell, points in that cell are added to our overall points.</li>
<li>We need to find minimum initial points to reach cell (m-1, n-1) from (0, 0) by following these certain set of rules :</li>
</ul>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li style="list-style-type: none;">
<ul>
<li>From a cell (i, j) we can move to (i+1, j) or (i, j+1).</li>
<li>We cannot move from (i, j) if your overall points at (i, j) is &lt;= 0.</li>
<li>We have to reach at (n-1, m-1) with minimum positive points i.e., &gt; 0.</li>
</ul>
</li>
</ul>
</div>
</div>
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="syntax" class="color-purple">Syntax</h2>
</div>
</div>
<div class="Output" style="text-align: justify;">
<div class="hddn">
<figure class="highlight">
<pre><code class="hljs scss" data-lang=""><span class="nt"><span class="hljs-function">minInitTokens</span>(matrix) </span></code></pre>
</figure>
</div>
</div>
<div class="TextHeading">
<div class="hddn">
<h2 id="sample-code-in-c" class="color-purple" style="text-align: justify;">Sample Code in C++</h2>
[pastacode lang=&#8221;cpp&#8221; manual=&#8221;%23include%3Ciostream%3E%0A%23include%3Ccmath%3E%0A%23define%20ROW%203%0A%23define%20COL%203%0Ausing%20namespace%20std%3B%0A%0Aint%20tokens%5BROW%5D%5BCOL%5D%20%3D%20%7B%0A%20%20%20%7B-2%2C-3%2C3%7D%2C%0A%20%20%20%7B-5%2C-10%2C1%7D%2C%0A%20%20%20%7B10%2C30%2C-5%7D%0A%7D%3B%0A%0Aint%20max(int%20a%2C%20int%20b)%20%7B%0A%20%20%20return%20(a%3Eb)%3Fa%3Ab%3B%0A%7D%0A%0Aint%20minInitPoints()%20%7B%0A%20%20%20int%20minToken%5BROW%5D%5BCOL%5D%3B%0A%20%20%20int%20m%20%3D%20ROW%2C%20n%20%3D%20COL%3B%0A%20%20%20%0A%20%20%20minToken%5Bm-1%5D%5Bn-1%5D%20%3D%20tokens%5Bm-1%5D%5Bn-1%5D%20%3E%200%3F%201%3A%20abs(tokens%5Bm-1%5D%5Bn-1%5D)%20%2B%201%3B%0A%20%20%20%0A%20%20%20for%20(int%20i%20%3D%20m-2%3B%20i%20%3E%3D%200%3B%20i&#8211;)%20%20%20%20%2F%2Ffrom%20last%20row%20to%20first%20row%2C%20fill%20points%0A%20%20%20%20%20%20minToken%5Bi%5D%5Bn-1%5D%20%3D%20max(minToken%5Bi%2B1%5D%5Bn-1%5D%20-%20tokens%5Bi%5D%5Bn-1%5D%2C%201)%3B%0A%20%20%20%0A%20%20%20for%20(int%20j%20%3D%20n-2%3B%20j%20%3E%3D%200%3B%20j&#8211;)%20%20%20%20%2F%2Ffill%20last%20column%20to%20first%20column%2C%20fill%20points%0A%20%20%20%20%20%20minToken%5Bm-1%5D%5Bj%5D%20%3D%20max(minToken%5Bm-1%5D%5Bj%2B1%5D%20-%20tokens%5Bm-1%5D%5Bj%5D%2C%201)%3B%0A%0A%20%20%20for%20(int%20i%3Dm-2%3B%20i%3E%3D0%3B%20i&#8211;)%20%7B%0A%20%20%20%20%20%20for%20(int%20j%3Dn-2%3B%20j%3E%3D0%3B%20j&#8211;)%20%7B%0A%20%20%20%20%20%20%20%20%20int%20remPoint%20%3D%20min(minToken%5Bi%2B1%5D%5Bj%5D%2C%20minToken%5Bi%5D%5Bj%2B1%5D)%3B%20%20%20%20%2F%2Fcalculate%20remaining%20points%0A%20%20%20%20%20%20%20%20%20minToken%5Bi%5D%5Bj%5D%20%3D%20max(remPoint%20-%20tokens%5Bi%5D%5Bj%5D%2C%201)%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%7D%0A%20%20%20return%20minToken%5B0%5D%5B0%5D%3B%0A%7D%0A%0Aint%20main()%20%7B%0A%20%20%20cout%20%3C%3C%20%22Least%20Points%20Required%3A%20%22%20%3C%3C%20minInitPoints()%3B%0A%7D&#8221; message=&#8221;&#8221; highlight=&#8221;&#8221; provider=&#8221;manual&#8221;/]
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="output" class="color-purple">Output</h2>
</div>
</div>
<div class="Output">
<div class="hddn">
<figure class="highlight" style="text-align: justify;">
<pre><code class="hljs" data-lang=""><span class="nt">Least Points Required: 7</span></code></pre>
</figure>
</div>
</div>
</div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.wikitechy.com/interview-questions/data-structure/what-are-the-minimum-initial-points-to-reach-destination/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Delete all occurrences of a given key in a linked list ?</title>
		<link>https://www.wikitechy.com/interview-questions/data-structure/delete-all-occurrences-of-a-given-key-in-a-linked-list/</link>
					<comments>https://www.wikitechy.com/interview-questions/data-structure/delete-all-occurrences-of-a-given-key-in-a-linked-list/#respond</comments>
		
		<dc:creator><![CDATA[Editor]]></dc:creator>
		<pubDate>Tue, 13 Jul 2021 17:39:53 +0000</pubDate>
				<category><![CDATA[Data Structure]]></category>
		<category><![CDATA[Accenture interview questions and answers]]></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[c program to delete first node in linked list]]></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[delete a specific node in linked list java]]></category>
		<category><![CDATA[delete all nodes in doubly linked list c++]]></category>
		<category><![CDATA[delete at position in a doubly linked list]]></category>
		<category><![CDATA[delete first node in linked list c++]]></category>
		<category><![CDATA[delete last node in doubly linked list in c++]]></category>
		<category><![CDATA[delete last node in linked list c++]]></category>
		<category><![CDATA[delete last node in linked list in c]]></category>
		<category><![CDATA[delete node at given position in a linked list in c++]]></category>
		<category><![CDATA[delete node from doubly linked list java]]></category>
		<category><![CDATA[Dell International Services India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[doubly linked list geeksforgeeks]]></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[IBM interview questions and answers]]></category>
		<category><![CDATA[Indecomm Global Services interview questions and answers]]></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[remove element from doubly linked list c++]]></category>
		<category><![CDATA[samsung interview questions and answers]]></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[Tech Mahindra interview questions and answers]]></category>
		<category><![CDATA[Tracxn Technologies Pvt Ltd interview questions and answers]]></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[write a program to delete a node from linked list in c++]]></category>
		<category><![CDATA[write ac program to delete a particular element in the doubly linked list]]></category>
		<category><![CDATA[write an algorithm to delete duplicate elements in a singly linked list]]></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=509</guid>

					<description><![CDATA[Answer : Given a singly linked list, delete all occurrences...]]></description>
										<content:encoded><![CDATA[<div class="TextHeading">
<div class="hddn">
<h2 id="delete-all-occurrences-of-a-given-key-in-a-linked-list" class="color-pink">Delete all occurrences of a given key in a linked list ?</h2>
</div>
</div>
<div class="CodeContent">
<div class="hddn">
<ul>
<li>Given a singly linked list, delete all occurrences of a given key in it. For example,</li>
</ul>
[pastacode lang=&#8221;markdown&#8221; manual=&#8221;Input%3A%20%202%20-%3E%201%20-%3E%208%20-%3E%202%20-%3E%20%203%20-%3E%20%202%20-%3E%207%0A%20%20%20%20%20%20%20Key%20to%20delete%20%3D%202%0AOutput%3A%20%201%20-%3E%208%20-%3E%203%20-%3E%207%20&#8243; message=&#8221;&#8221; highlight=&#8221;&#8221; provider=&#8221;manual&#8221;/]
<h2 id="sample-code-in-c" class="color-purple">Sample Code in C</h2>
[pastacode lang=&#8221;c&#8221; manual=&#8221;%23include%20%3Cstdio.h%3E%20%0A%23include%20%3Cstdlib.h%3E%20%0A%2F%2F%20A%20linked%20list%20node%20%0Astruct%20Node%20%0A%7B%20%0A%20%20%20%20int%20data%3B%20%0A%20%20%20%20struct%20Node%20*next%3B%20%0A%7D%3B%20%0A%2F*%20Given%20a%20reference%20(pointer%20to%20pointer)%20to%20the%20head%20of%20a%20list%20%0A%20%20%20and%20an%20int%2C%20inserts%20a%20new%20node%20on%20the%20front%20of%20the%20list.%20*%2F%0Avoid%20push(struct%20Node**%20head_ref%2C%20int%20new_data)%20%0A%7B%20%0A%20%20%20%20struct%20Node*%20new_node%20%3D%20(struct%20Node*)%20malloc(sizeof(struct%20Node))%3B%20%0A%20%20%20%20new_node-%3Edata%20%20%3D%20new_data%3B%20%0A%20%20%20%20new_node-%3Enext%20%3D%20(*head_ref)%3B%20%0A%20%20%20%20(*head_ref)%20%20%20%20%3D%20new_node%3B%20%0A%7D%20%0A%2F*%20Given%20a%20reference%20(pointer%20to%20pointer)%20to%20the%20head%20of%20a%20list%20and%20%0A%20%20%20a%20key%2C%20deletes%20all%20occurrence%20of%20the%20given%20key%20in%20linked%20list%20*%2F%0Avoid%20deleteKey(struct%20Node%20**head_ref%2C%20int%20key)%20%0A%7B%20%0A%20%20%20%20%2F%2F%20Store%20head%20node%20%0A%20%20%20%20struct%20Node*%20temp%20%3D%20*head_ref%2C%20*prev%3B%20%0A%20%20%20%20%2F%2F%20If%20head%20node%20itself%20holds%20the%20key%20or%20multiple%20occurrences%20of%20key%20%0A%20%20%20%20while%20(temp%20!%3D%20NULL%20%26%26%20temp-%3Edata%20%3D%3D%20key)%20%0A%20%20%20%20%7B%20%0A%20%20%20%20%20%20%20%20*head_ref%20%3D%20temp-%3Enext%3B%20%20%20%2F%2F%20Changed%20head%20%0A%20%20%20%20%20%20%20%20free(temp)%3B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20free%20old%20head%20%0A%20%20%20%20%20%20%20%20temp%20%3D%20*head_ref%3B%20%20%20%20%20%20%20%20%20%2F%2F%20Change%20Temp%20%0A%20%20%20%20%7D%20%0A%20%20%20%20%2F%2F%20Delete%20occurrences%20other%20than%20head%20%0A%20%20%20%20while%20(temp%20!%3D%20NULL)%20%0A%20%20%20%20%7B%20%0A%20%20%20%20%20%20%20%20%2F%2F%20Search%20for%20the%20key%20to%20be%20deleted%2C%20keep%20track%20of%20the%20%0A%20%20%20%20%20%20%20%20%2F%2F%20previous%20node%20as%20we%20need%20to%20change%20&#8217;prev-%3Enext&#8217;%20%0A%20%20%20%20%20%20%20%20while%20(temp%20!%3D%20NULL%20%26%26%20temp-%3Edata%20!%3D%20key)%20%0A%20%20%20%20%20%20%20%20%7B%20%0A%20%20%20%20%20%20%20%20%20%20%20%20prev%20%3D%20temp%3B%20%0A%20%20%20%20%20%20%20%20%20%20%20%20temp%20%3D%20temp-%3Enext%3B%20%0A%20%20%20%20%20%20%20%20%7D%20%0A%20%20%20%20%20%20%20%20%2F%2F%20If%20key%20was%20not%20present%20in%20linked%20list%20%0A%20%20%20%20%20%20%20%20if%20(temp%20%3D%3D%20NULL)%20return%3B%20%0A%20%20%20%20%20%20%20%20%2F%2F%20Unlink%20the%20node%20from%20linked%20list%20%0A%20%20%20%20%20%20%20%20prev-%3Enext%20%3D%20temp-%3Enext%3B%20%0A%20%20%20%20%20%20%20%20free(temp)%3B%20%20%2F%2F%20Free%20memory%20%0A%20%20%20%20%20%20%20%20%2F%2FUpdate%20Temp%20for%20next%20iteration%20of%20outer%20loop%20%0A%20%20%20%20%20%20%20%20temp%20%3D%20prev-%3Enext%3B%20%0A%20%20%20%20%7D%20%0A%7D%20%0A%2F%2F%20This%20function%20prints%20contents%20of%20linked%20list%20starting%20from%20%0A%2F%2F%20the%20given%20node%20%0Avoid%20printList(struct%20Node%20*node)%20%0A%7B%20%0A%20%20%20%20while%20(node%20!%3D%20NULL)%20%0A%20%20%20%20%7B%20%0A%20%20%20%20%20%20%20%20printf(%22%20%25d%20%22%2C%20node-%3Edata)%3B%20%0A%20%20%20%20%20%20%20%20node%20%3D%20node-%3Enext%3B%20%0A%20%20%20%20%7D%20%0A%7D%20%0A%20%20%20%2F*%20Drier%20program%20to%20test%20above%20functions*%2F%0Aint%20main()%20%0A%7B%20%0A%20%20%20%20%2F*%20Start%20with%20the%20empty%20list%20*%2F%0A%20%20%20%20struct%20Node*%20head%20%3D%20NULL%3B%20%0A%20%20%20%20push(%26head%2C%207)%3B%20%0A%20%20%20%20push(%26head%2C%202)%3B%20%0A%20%20%20%20push(%26head%2C%203)%3B%20%0A%20%20%20%20push(%26head%2C%202)%3B%20%0A%20%20%20%20push(%26head%2C%208)%3B%20%0A%20%20%20%20push(%26head%2C%201)%3B%20%0A%20%20%20%20push(%26head%2C%202)%3B%20%0A%20%20%20%20push(%26head%2C%202)%3B%20%0A%20%20%20%20int%20key%20%3D%202%3B%20%2F%2F%20key%20to%20delete%20%0A%20%20%20%20puts(%22Created%20Linked%20List%3A%20%22)%3B%20%0A%20%20%20%20printList(head)%3B%20%0A%20%20%20%20deleteKey(%26head%2C%20key)%3B%20%0A%20%20%20%20puts(%22%5CnLinked%20List%20after%20Deletion%3A%20%22)%3B%20%0A%20%20%20%20printList(head)%3B%20%0A%20%20%20%20return%200%3B%20%0A%7D&#8221; message=&#8221;&#8221; highlight=&#8221;&#8221; provider=&#8221;manual&#8221;/]
<div class="TextHeading">
<div class="hddn">
<h2 id="output" class="color-purple">Output</h2>
</div>
</div>
<div class="Output">
<div class="hddn">
<figure class="highlight">
<pre><code class="hljs" data-lang=""><span class="nt">Created Linked List:
 2  2  1  8  2  3  2  7
Linked List after Deletion:
 1  8  3  7 </span></code></pre>
</figure>
</div>
</div>
</div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.wikitechy.com/interview-questions/data-structure/delete-all-occurrences-of-a-given-key-in-a-linked-list/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Write a program to reverse a string using stack data structure ?</title>
		<link>https://www.wikitechy.com/interview-questions/data-structure/write-a-program-to-reverse-a-string-using-stack-data-structure/</link>
					<comments>https://www.wikitechy.com/interview-questions/data-structure/write-a-program-to-reverse-a-string-using-stack-data-structure/#respond</comments>
		
		<dc:creator><![CDATA[Editor]]></dc:creator>
		<pubDate>Tue, 13 Jul 2021 11:18:34 +0000</pubDate>
				<category><![CDATA[Data Structure]]></category>
		<category><![CDATA[Accenture interview questions and answers]]></category>
		<category><![CDATA[algorithm for palindrome using stack]]></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[data structure to reverse string ( other than stack)]]></category>
		<category><![CDATA[Dell International Services India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[Flipkart interview questions and answers]]></category>
		<category><![CDATA[geekyants 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 push a string into a stack in c]]></category>
		<category><![CDATA[how to reverse a stack in c++]]></category>
		<category><![CDATA[IBM interview questions and answers]]></category>
		<category><![CDATA[Indecomm Global Services interview questions and answers]]></category>
		<category><![CDATA[java input string]]></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[rereverse a string using stack in cstack string java]]></category>
		<category><![CDATA[reverse a linked list using stack in c]]></category>
		<category><![CDATA[reverse a list using stack in c]]></category>
		<category><![CDATA[reverse a number using stack]]></category>
		<category><![CDATA[reverse a number using stack in c]]></category>
		<category><![CDATA[reverse a string in java]]></category>
		<category><![CDATA[reverse a string using stack c++]]></category>
		<category><![CDATA[reverse a string using stack in c#]]></category>
		<category><![CDATA[reverse a string using stack in java]]></category>
		<category><![CDATA[reverse a string using stack in python]]></category>
		<category><![CDATA[reverse string using stack data structure in c]]></category>
		<category><![CDATA[reverse string using stack in java]]></category>
		<category><![CDATA[reverse words in a string using stack]]></category>
		<category><![CDATA[reverse words in a string using stack c++]]></category>
		<category><![CDATA[samsung interview questions and answers]]></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[stack string java]]></category>
		<category><![CDATA[Tech Mahindra interview questions and answers]]></category>
		<category><![CDATA[Tracxn Technologies Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[UnitedHealth Group interview questions and answers]]></category>
		<category><![CDATA[use a stack to reverse the words of a sentence]]></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[write a program to reverse a string using stack data structu]]></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=478</guid>

					<description><![CDATA[Answer : Given a string, reverse it using stack...]]></description>
										<content:encoded><![CDATA[<div class="TextHeading">
<div class="hddn">
<h2 id="write-a-program-to-reverse-a-string-using-stack-data-structure" class="color-pink" style="text-align: justify;">Write a program to reverse a string using stack data structure ?</h2>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li>Given a string, reverse it using stack. For example <a href="https://www.wikitechy.com/" target="_blank" rel="noopener">“Wikitechy”</a> should be converted to “yhcetikiW”.</li>
<li>Following is simple algorithm to reverse a string using stack.</li>
</ul>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li style="list-style-type: none;">
<ul>
<li>Empty stack to be created.</li>
<li><a href="https://www.wikitechy.com/tutorials/javascript/creating-multiline-string-in-javascript" target="_blank" rel="noopener">String</a> to stack put one by one push all characters.</li>
<li>From the stack and put them back to string one by one pop all characters.</li>
</ul>
</li>
</ul>
</div>
</div>
<div class="ImageContent">
<div class="hddn"><img decoding="async" class="img-responsive center-block aligncenter" src="https://cdn.wikitechy.com/interview-questions/data-structure/reserve-a-string-using-stack.jpg" alt=" Reserve a String Using Stack" /></div>
<div>
<h2 id="sample-code-in-java" class="color-purple" style="text-align: justify;">Sample Code in Java</h2>
[pastacode lang=&#8221;javascript&#8221; manual=&#8221;import%20java.util.*%3B%20%0A%20%20%0A%2F%2Fstack%20%0Aclass%20Stack%20%0A%7B%20%0A%20%20%20%20int%20size%3B%20%0A%20%20%20%20int%20top%3B%20%0A%20%20%20%20char%5B%5D%20a%3B%20%20%0A%20%20%0A%20%20%20%20%2F%2Ffunction%20to%20check%20if%20stack%20is%20empty%20%0A%20%20%20%20boolean%20isEmpty()%20%0A%20%20%20%20%7B%20%0A%20%20%20%20%20%20%20%20return%20(top%20%3C%200)%3B%20%0A%20%20%20%20%7D%20%0A%20%20%20%20%20%20%0A%20%20%20%20Stack(int%20n)%20%0A%20%20%20%20%7B%20%0A%20%20%20%20%20%20%20%20top%20%3D%20-1%3B%20%0A%20%20%20%20%20%20%20%20size%20%3D%20n%3B%20%0A%20%20%20%20%20%20%20%20a%20%3D%20new%20char%5Bsize%5D%3B%20%0A%20%20%20%20%7D%20%0A%20%20%0A%20%20%20%20%2F%2Ffunction%20to%20push%20element%20in%20Stack%20%0A%20%20%20%20boolean%20push(char%20x)%20%0A%20%20%20%20%7B%20%0A%20%20%20%20%20%20%20%20if%20(top%20%3E%3D%20size)%20%0A%20%20%20%20%20%20%20%20%7B%20%0A%20%20%20%20%20%20%20%20System.out.println(%22Stack%20Overflow%22)%3B%20%0A%20%20%20%20%20%20%20%20return%20false%3B%20%0A%20%20%20%20%20%20%20%20%7D%20%0A%20%20%20%20%20%20%20%20else%0A%20%20%20%20%20%20%20%20%7B%20%0A%20%20%20%20%20%20%20%20%20%20%20%20a%5B%2B%2Btop%5D%20%3D%20x%3B%20%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20true%3B%20%0A%20%20%20%20%20%20%20%20%7D%20%0A%20%20%20%20%7D%20%0A%20%20%0A%20%20%20%20%2F%2Ffunction%20to%20pop%20element%20from%20stack%20%0A%20%20%20%20char%20pop()%20%0A%20%20%20%20%7B%20%0A%20%20%20%20%20%20%20%20if%20(top%20%3C%200)%20%0A%20%20%20%20%20%20%20%20%7B%20%0A%20%20%20%20%20%20%20%20System.out.println(%22Stack%20Underflow%22)%3B%20%0A%20%20%20%20%20%20%20%20return%200%3B%20%0A%20%20%20%20%20%20%20%20%7D%20%0A%20%20%20%20%20%20%20%20else%0A%20%20%20%20%20%20%20%20%7B%20%0A%20%20%20%20%20%20%20%20%20%20%20%20char%20x%20%3D%20a%5Btop&#8211;%5D%3B%20%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20x%3B%20%0A%20%20%20%20%20%20%20%20%7D%20%0A%20%20%20%20%7D%20%0A%7D%20%0A%20%20%0A%20%20%0A%2F%2F%20Driver%20code%20%0Aclass%20Main%20%0A%7B%20%0A%20%20%20%20%2F%2Ffunction%20to%20reverse%20the%20string%20%0A%20%20%20%20public%20static%20void%20reverse(StringBuffer%20str)%20%0A%20%20%20%20%7B%20%0A%20%20%20%20%20%20%20%20%2F%2F%20Create%20a%20stack%20of%20capacity%20%20%0A%20%20%20%20%20%20%20%20%2F%2F%20equal%20to%20length%20of%20string%20%0A%20%20%20%20%20%20%20%20int%20n%20%3D%20str.length()%3B%20%0A%20%20%20%20%20%20%20%20Stack%20obj%20%3D%20new%20Stack(n)%3B%20%0A%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%2F%2F%20Push%20all%20characters%20of%20string%20%20%0A%20%20%20%20%20%20%20%20%2F%2F%20to%20stack%20%0A%20%20%20%20%20%20%20%20int%20i%3B%20%0A%20%20%20%20%20%20%20%20for%20(i%20%3D%200%3B%20i%20%3C%20n%3B%20i%2B%2B)%20%0A%20%20%20%20%20%20%20%20obj.push(str.charAt(i))%3B%20%0A%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%2F%2F%20Pop%20all%20characters%20of%20string%20%20%0A%20%20%20%20%20%20%20%20%2F%2F%20and%20put%20them%20back%20to%20str%20%0A%20%20%20%20%20%20%20%20for%20(i%20%3D%200%3B%20i%20%3C%20n%3B%20i%2B%2B)%20%0A%20%20%20%20%20%20%20%20%7B%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20char%20ch%20%3D%20obj.pop()%3B%20%0A%20%20%20%20%20%20%20%20%20%20%20%20str.setCharAt(i%2Cch)%3B%20%0A%20%20%20%20%20%20%20%20%7D%20%0A%20%20%20%20%7D%20%20%0A%20%20%20%20%20%20%0A%20%20%20%20%2F%2Fdriver%20function%20%0A%20%20%20%20public%20static%20void%20main(String%20args%5B%5D)%20%0A%20%20%20%20%7B%20%0A%20%20%20%20%20%20%20%20%2F%2Fcreate%20a%20new%20string%20%0A%20%20%20%20%20%20%20%20StringBuffer%20s%3D%20new%20StringBuffer(%22Wikitechy%22)%3B%20%0A%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%2F%2Fcall%20reverse%20method%20%0A%20%20%20%20%20%20%20%20reverse(s)%3B%20%0A%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%2F%2Fprint%20the%20reversed%20string%20%0A%20%20%20%20%20%20%20%20System.out.println(%22Reversed%20string%20is%20%22%20%2B%20s)%3B%20%0A%20%20%20%20%7D%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="output" class="color-blue">Output</h2>
</div>
</div>
<div class="CodeContent" style="text-align: justify;">
<div class="hddn">
<figure class="highlight">
<pre><code id="code1" class="hljs typescript" data-lang=""><span class="nt">Reversed <span class="hljs-built_in">string</span> is yhcetikiW.
</span></code></pre>
</figure>
</div>
</div>
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="time-complexity" class="color-blue">Time Complexity:</h2>
</div>
</div>
<div class="Content">
<div class="hddn">
<ul>
<li style="text-align: justify;">O(n) where n is number of characters in stack.</li>
</ul>
</div>
</div>
</div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.wikitechy.com/interview-questions/data-structure/write-a-program-to-reverse-a-string-using-stack-data-structure/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Detect loop in a linked list ?</title>
		<link>https://www.wikitechy.com/interview-questions/data-structure/detect-loop-in-a-linked-list/</link>
					<comments>https://www.wikitechy.com/interview-questions/data-structure/detect-loop-in-a-linked-list/#respond</comments>
		
		<dc:creator><![CDATA[Editor]]></dc:creator>
		<pubDate>Tue, 13 Jul 2021 11:08:43 +0000</pubDate>
				<category><![CDATA[Data Structure]]></category>
		<category><![CDATA[Accenture interview questions and answers]]></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[Dell International Services India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[find length of linked list java]]></category>
		<category><![CDATA[find length of loop in linked list]]></category>
		<category><![CDATA[find length of loop in linked list in java]]></category>
		<category><![CDATA[find start of loop in linked list]]></category>
		<category><![CDATA[find start of loop in linked list java]]></category>
		<category><![CDATA[Flipkart interview questions and answers]]></category>
		<category><![CDATA[floyd's cycle detection algorithm]]></category>
		<category><![CDATA[for loop linked list c++]]></category>
		<category><![CDATA[Genpact interview questions and answers]]></category>
		<category><![CDATA[Globallogic India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[IBM interview questions and answers]]></category>
		<category><![CDATA[Indecomm Global Services interview questions and answers]]></category>
		<category><![CDATA[java detect]]></category>
		<category><![CDATA[length of loop in linked list]]></category>
		<category><![CDATA[length of loop in linked list java]]></category>
		<category><![CDATA[linked list algorithm]]></category>
		<category><![CDATA[linked list in data structure]]></category>
		<category><![CDATA[linked list program in c with explanation]]></category>
		<category><![CDATA[linked list program in clinked list algorithm]]></category>
		<category><![CDATA[Mphasis interview questions and answers]]></category>
		<category><![CDATA[n'th node from end of linked list]]></category>
		<category><![CDATA[NetApp interview questions and answers]]></category>
		<category><![CDATA[Oracle Corporation interview questions and answers]]></category>
		<category><![CDATA[reverse a linked list]]></category>
		<category><![CDATA[samsung interview questions and answers]]></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[Tech Mahindra interview questions and answers]]></category>
		<category><![CDATA[telibrahma interview questions and answers]]></category>
		<category><![CDATA[Tracxn Technologies Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[UnitedHealth Group interview questions and answers]]></category>
		<category><![CDATA[what is loop]]></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=473</guid>

					<description><![CDATA[Answer : There are two ways to detect loop in linked list...
]]></description>
										<content:encoded><![CDATA[<div class="TextHeading">
<div class="hddn">
<h2 id="detect-loop-in-a-linked-list" class="color-pink">Detect loop in a linked list ?</h2>
</div>
</div>
<div class="Content">
<div class="hddn">
<ul>
<li>There are two ways to detect loop in linked list or not.</li>
</ul>
</div>
</div>
<div class="ImageContent">
<div class="hddn"><img decoding="async" class="img-responsive center-block aligncenter" src="https://cdn.wikitechy.com/interview-questions/data-structure/detect-loop-in-a-linked-list.png" alt=" Detect Loop in a Linked List" /></div>
</div>
<div class="TextHeading">
<div class="hddn">
<h2 id="method-1" class="color-blue">Method 1:</h2>
</div>
</div>
<div class="Content">
<div class="hddn">
<ul>
<li>Traverse through each node till end , tracking visited node using Hash map.</li>
<li>If you find node that is already visited, then there is a loop in LinkedList</li>
<li>If you reach till end while traversing then there is no loop in LinkedList</li>
</ul>
[pastacode lang=&#8221;markdown&#8221; manual=&#8221;using%20namespace%20std%3B%20%0A%0Astruct%20Node%20%0A%7B%20%0A%09int%20data%3B%20%0A%09struct%20Node*%20next%3B%20%0A%7D%3B%20%0A%0Avoid%20push(struct%20Node**%20head_ref%2C%20int%20new_data)%20%0A%7B%20%0A%0A%09struct%20Node*%20new_node%20%3D%20new%20Node%3B%20%0A%0A%09%0A%09new_node-%3Edata%20%3D%20new_data%3B%20%0A%0A%09%2F*%20link%20the%20old%20list%20off%20the%20new%20node%20*%2F%0A%09new_node-%3Enext%20%3D%20(*head_ref)%3B%20%0A%0A%09%2F*%20move%20the%20head%20to%20point%20to%20the%20new%20node%20*%2F%0A%09(*head_ref)%20%3D%20new_node%3B%20%0A%7D%20%0A%0A%2F%2F%20Returns%20true%20if%20there%20is%20a%20loop%20in%20linked%20list%20%0A%2F%2F%20else%20returns%20false.%20%0Abool%20detectLoop(struct%20Node%20*h)%20%0A%7B%20%0A%09unordered_set%3CNode%20*%3E%20s%3B%20%0A%09while%20(h%20!%3D%20NULL)%20%0A%09%7B%20%0A%09%09%2F%2F%20If%20this%20node%20is%20already%20present%20%0A%09%09%2F%2F%20in%20hashmap%20it%20means%20there%20is%20a%20cycle%20%0A%09%09%2F%2F%20(Because%20you%20we%20encountering%20the%20%0A%09%09%2F%2F%20node%20for%20the%20second%20time).%20%0A%09%09if%20(s.find(h)%20!%3D%20s.end())%20%0A%09%09%09return%20true%3B%20%0A%0A%09%09%2F%2F%20If%20we%20are%20seeing%20the%20node%20for%20%0A%09%09%2F%2F%20the%20first%20time%2C%20insert%20it%20in%20hash%20%0A%09%09s.insert(h)%3B%20%0A%0A%09%09h%20%3D%20h-%3Enext%3B%20%0A%09%7D%20%0A%0A%09return%20false%3B%20%0A%7D%20%0A%0A%2F*%20Drier%20program%20to%20test%20above%20function*%2F%0Aint%20main()%20%0A%7B%20%0A%09%2F*%20Start%20with%20the%20empty%20list%20*%2F%0A%09struct%20Node*%20head%20%3D%20NULL%3B%20%0A%0A%09push(%26head%2C%2021)%3B%20%0A%09push(%26head%2C%2014)%3B%20%0A%09push(%26head%2C%205)%3B%20%0A%09push(%26head%2C%2010)%3B%20%0A%0A%09%2F*%20Create%20a%20loop%20for%20testing%20*%2F%0A%09head-%3Enext-%3Enext-%3Enext-%3Enext%20%3D%20head%3B%20%0A%0A%09if%20(detectLoop(head))%20%0A%09%09cout%20%3C%3C%20%22Loop%20found%22%3B%20%0A%09else%0A%09%09cout%20%3C%3C%20%22No%20Loop%22%3B%20%0A%0A%09return%200%3B%20%0A%7D%20&#8243; message=&#8221;&#8221; highlight=&#8221;&#8221; provider=&#8221;manual&#8221;/]
<div class="TextHeading">
<div class="hddn">
<h2 id="output" class="color-blue">Output:</h2>
<p><code class="hljs" data-lang=""><span class="nt">Loop found</span></code></p>
</div>
<div class="TextHeading">
<div class="hddn">
<h2 id="method-2" class="color-blue">Method 2:</h2>
</div>
</div>
<div class="Content">
<div class="hddn">
<ul>
<li>Efficient approach for this problem would be Floyd’s cycle detection algorithm, so steps for this algorithm would be:</li>
</ul>
</div>
</div>
<div class="Content">
<div class="hddn">
<ul>
<li style="list-style-type: none;">
<ul>
<li>Use two pointer fastPtr and slowPtr and initialize both to head of linkedlist</li>
<li>Move fastPtr by two nodes and slowPtr by one node in each iteration.</li>
<li>If fastPtr and slowPtr meet at some iteration , then there is a loop in linkedlist.</li>
<li>If fastPtr reaches to the end of linkedlist without meeting slow pointer then there is no loop in linkedlist (i.e fastPtr-&gt;next or fastPtr-&gt;next-&gt;next become null).</li>
</ul>
</li>
</ul>
[pastacode lang=&#8221;c&#8221; manual=&#8221;%2F%2F%20C%20program%20to%20detect%20loop%20in%20a%20linked%20list%20%0A%23include%3Cstdio.h%3E%20%0A%23include%3Cstdlib.h%3E%20%0A%2F*%20Link%20list%20node%20*%2F%0Astruct%20Node%20%0A%7B%20%0A%09int%20data%3B%20%0A%09struct%20Node*%20next%3B%20%0A%7D%3B%20%0A%0Avoid%20push(struct%20Node**%20head_ref%2C%20int%20new_data)%20%0A%7B%20%0A%09%2F*%20allocate%20node%20*%2F%0A%09struct%20Node*%20new_node%20%3D%20%0A%09%09(struct%20Node*)%20malloc(sizeof(struct%20Node))%3B%20%0A%0A%09%2F*%20put%20in%20the%20data%20*%2F%0A%09new_node-%3Edata%20%3D%20new_data%3B%20%0A%0A%09%2F*%20link%20the%20old%20list%20off%20the%20new%20node%20*%2F%0A%09new_node-%3Enext%20%3D%20(*head_ref)%3B%20%0A%0A%09%2F*%20move%20the%20head%20to%20point%20to%20the%20new%20node%20*%2F%0A%09(*head_ref)%20%3D%20new_node%3B%20%0A%7D%20%0A%0Aint%20detectloop(struct%20Node%20*list)%20%0A%7B%20%0A%09struct%20Node%20*slow_p%20%3D%20list%2C%20*fast_p%20%3D%20list%3B%20%0A%0A%09while%20(slow_p%20%26%26%20fast_p%20%26%26%20fast_p-%3Enext%20)%20%0A%09%7B%20%0A%09%09slow_p%20%3D%20slow_p-%3Enext%3B%20%0A%09%09fast_p%20%3D%20fast_p-%3Enext-%3Enext%3B%20%0A%09%09if%20(slow_p%20%3D%3D%20fast_p)%20%0A%09%09%7B%20%0A%09%09printf(%22Found%20Loop%22)%3B%20%0A%09%09return%201%3B%20%0A%09%09%7D%20%0A%09%7D%20%0A%09return%200%3B%20%0A%7D%20%0A%0A%2F*%20Drier%20program%20to%20test%20above%20function*%2F%0Aint%20main()%20%0A%7B%20%0A%09%2F*%20Start%20with%20the%20empty%20list%20*%2F%0A%09struct%20Node*%20head%20%3D%20NULL%3B%20%0A%0A%09push(%26head%2C%2010)%3B%20%0A%09push(%26head%2C%204)%3B%20%0A%09push(%26head%2C%205)%3B%20%0A%09push(%26head%2C%2010)%3B%20%0A%0A%09%2F*%20Create%20a%20loop%20for%20testing%20*%2F%0A%09head-%3Enext-%3Enext-%3Enext-%3Enext%20%3D%20head%3B%20%0A%09detectloop(head)%3B%20%0A%0A%09return%200%3B%20%0A%7D&#8221; message=&#8221;&#8221; highlight=&#8221;&#8221; provider=&#8221;manual&#8221;/]
<div class="TextHeading">
<div class="hddn">
<h2 id="output-2" class="color-blue">Output:</h2>
</div>
</div>
<div class="CodeContent">
<div class="hddn">
<figure class="highlight">
<pre><code id="code2" class="hljs" data-lang=""><span class="nt">Found Loop</span></code></pre>
</figure>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.wikitechy.com/interview-questions/data-structure/detect-loop-in-a-linked-list/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
