<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: The Amazon SDE Phone Interview 2</title>
	<atom:link href="http://www.oliyiptong.com/blog/2006/05/24/the-amazon-phone-interview-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.oliyiptong.com/blog/2006/05/24/the-amazon-phone-interview-2/</link>
	<description></description>
	<pubDate>Thu, 04 Dec 2008 18:53:43 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: zdmytriv</title>
		<link>http://www.oliyiptong.com/blog/2006/05/24/the-amazon-phone-interview-2/#comment-40234</link>
		<dc:creator>zdmytriv</dc:creator>
		<pubDate>Sun, 27 Jan 2008 01:33:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.oliyiptong.com/blog/?p=7#comment-40234</guid>
		<description>Quicksort will take O(n)
then compare for each i=0..n: (a[i] + a[i+1])  
O(n) + O(n) = O(2n) = O(n)</description>
		<content:encoded><![CDATA[<p>Quicksort will take O(n)<br />
then compare for each i=0..n: (a[i] + a[i+1])<br />
O(n) + O(n) = O(2n) = O(n)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gowrishankar</title>
		<link>http://www.oliyiptong.com/blog/2006/05/24/the-amazon-phone-interview-2/#comment-38688</link>
		<dc:creator>Gowrishankar</dc:creator>
		<pubDate>Thu, 03 Jan 2008 14:27:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.oliyiptong.com/blog/?p=7#comment-38688</guid>
		<description>Hi Oliver,

could you explain me the solution you gave for the 4 player client-server architecture game?

Thanks
Gowri</description>
		<content:encoded><![CDATA[<p>Hi Oliver,</p>
<p>could you explain me the solution you gave for the 4 player client-server architecture game?</p>
<p>Thanks<br />
Gowri</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kc</title>
		<link>http://www.oliyiptong.com/blog/2006/05/24/the-amazon-phone-interview-2/#comment-1195</link>
		<dc:creator>kc</dc:creator>
		<pubDate>Wed, 31 Jan 2007 05:45:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.oliyiptong.com/blog/?p=7#comment-1195</guid>
		<description>what about this

put them into a hash
for 1 - n item{
  if n&#62;= 10 next;
     push n to hash as a key
}

for 1 - n item {
  if n&#62;= 10 next;
  if hash [10-n] exisits  
     print n, 10-n 
}


0(n)</description>
		<content:encoded><![CDATA[<p>what about this</p>
<p>put them into a hash<br />
for 1 - n item{<br />
  if n&gt;= 10 next;<br />
     push n to hash as a key<br />
}</p>
<p>for 1 - n item {<br />
  if n&gt;= 10 next;<br />
  if hash [10-n] exisits<br />
     print n, 10-n<br />
}</p>
<p>0(n)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: oli</title>
		<link>http://www.oliyiptong.com/blog/2006/05/24/the-amazon-phone-interview-2/#comment-114</link>
		<dc:creator>oli</dc:creator>
		<pubDate>Mon, 31 Jul 2006 18:10:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.oliyiptong.com/blog/?p=7#comment-114</guid>
		<description>A hash table insertion is O(1) if you use chaining as a collision resolution strategy. But its search time is potentially O(n). A running time of O(1) for search is possible, but its the best case solution, i.e. when there has been no collision.

The solution that I came up with is as follows:

Assume list is sorted (even if it isn't, it can be sorted in O(n)) &#038; that there are no duplicates.
Have a pointer p1 point to the beginning of the list, and have a pointer p2 point to the end of the list.

while( indexOf(p1) != indexOf(p2) &#124;&#124; indexOf(p1) &gt; indexOf(p2))
    sum= p1+p2
    if (sum &lt; 10)
        p1++
    else if (sum &gt; 10)
        p2--
    else
        // sum == 10
        print p1, p2
        p1++
        p2--

effectively, the algorithm runs through the list only once and prints out every pair that's adds up to 10</description>
		<content:encoded><![CDATA[<p>A hash table insertion is O(1) if you use chaining as a collision resolution strategy. But its search time is potentially O(n). A running time of O(1) for search is possible, but its the best case solution, i.e. when there has been no collision.</p>
<p>The solution that I came up with is as follows:</p>
<p>Assume list is sorted (even if it isn&#8217;t, it can be sorted in O(n)) &#038; that there are no duplicates.<br />
Have a pointer p1 point to the beginning of the list, and have a pointer p2 point to the end of the list.</p>
<p>while( indexOf(p1) != indexOf(p2) || indexOf(p1) > indexOf(p2))<br />
    sum= p1+p2<br />
    if (sum < 10)<br />
        p1++<br />
    else if (sum > 10)<br />
        p2&#8211;<br />
    else<br />
        // sum == 10<br />
        print p1, p2<br />
        p1++<br />
        p2&#8211;</p>
<p>effectively, the algorithm runs through the list only once and prints out every pair that&#8217;s adds up to 10</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mr Fuji</title>
		<link>http://www.oliyiptong.com/blog/2006/05/24/the-amazon-phone-interview-2/#comment-110</link>
		<dc:creator>Mr Fuji</dc:creator>
		<pubDate>Sun, 30 Jul 2006 05:42:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.oliyiptong.com/blog/?p=7#comment-110</guid>
		<description>hmm okay after a little thought, does this sound correct?

o(log n) solution: 

foreach item in the list  //O(n)
do a binary search for 10 - item (if result is negative, skip)  // O(log n)

total time O(nlogn)

o(n) solution:

foreach item in the list //O(n)
int diff = 10 - item  //O(1)
search hash table for key (diff) //O(1)

total time O(n)</description>
		<content:encoded><![CDATA[<p>hmm okay after a little thought, does this sound correct?</p>
<p>o(log n) solution: </p>
<p>foreach item in the list  //O(n)<br />
do a binary search for 10 - item (if result is negative, skip)  // O(log n)</p>
<p>total time O(nlogn)</p>
<p>o(n) solution:</p>
<p>foreach item in the list //O(n)<br />
int diff = 10 - item  //O(1)<br />
search hash table for key (diff) //O(1)</p>
<p>total time O(n)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mr Fuji</title>
		<link>http://www.oliyiptong.com/blog/2006/05/24/the-amazon-phone-interview-2/#comment-109</link>
		<dc:creator>Mr Fuji</dc:creator>
		<pubDate>Sun, 30 Jul 2006 05:22:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.oliyiptong.com/blog/?p=7#comment-109</guid>
		<description>what's the solution to the question where you find all pairs adding up to 10? i know the o(n ^2) solution heh.

how does the binary search and o(n) search work?</description>
		<content:encoded><![CDATA[<p>what&#8217;s the solution to the question where you find all pairs adding up to 10? i know the o(n ^2) solution heh.</p>
<p>how does the binary search and o(n) search work?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: BTM</title>
		<link>http://www.oliyiptong.com/blog/2006/05/24/the-amazon-phone-interview-2/#comment-13</link>
		<dc:creator>BTM</dc:creator>
		<pubDate>Mon, 29 May 2006 21:29:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.oliyiptong.com/blog/?p=7#comment-13</guid>
		<description>Congratulations on getting into the 3rd round of interview!  I hope everything goes well for you tomorrow :D</description>
		<content:encoded><![CDATA[<p>Congratulations on getting into the 3rd round of interview!  I hope everything goes well for you tomorrow <img src='http://www.oliyiptong.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: 10101</title>
		<link>http://www.oliyiptong.com/blog/2006/05/24/the-amazon-phone-interview-2/#comment-12</link>
		<dc:creator>10101</dc:creator>
		<pubDate>Mon, 29 May 2006 00:28:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.oliyiptong.com/blog/?p=7#comment-12</guid>
		<description>I know the difference between an array and a linked list....YES!!!! But that's pretty much it for me...unemployment here I come!</description>
		<content:encoded><![CDATA[<p>I know the difference between an array and a linked list&#8230;.YES!!!! But that&#8217;s pretty much it for me&#8230;unemployment here I come!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Raphy C</title>
		<link>http://www.oliyiptong.com/blog/2006/05/24/the-amazon-phone-interview-2/#comment-11</link>
		<dc:creator>Raphy C</dc:creator>
		<pubDate>Sat, 27 May 2006 05:18:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.oliyiptong.com/blog/?p=7#comment-11</guid>
		<description>I understood NOTHING from that post but it's still nice to see you have a lot to say.</description>
		<content:encoded><![CDATA[<p>I understood NOTHING from that post but it&#8217;s still nice to see you have a lot to say.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.956 seconds -->
