<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>20bits - Latest Comments in Interview Questions: Two Bowling Balls | 20bits</title><link>http://20bits.disqus.com/</link><description></description><language>en</language><lastBuildDate>Thu, 12 Mar 2009 18:38:40 -0000</lastBuildDate><item><title>Re: Interview Questions: Two Bowling Balls | 20bits</title><link>http://20bits.com/articles/interview-questions-two-bowling-balls/#comment-7154851</link><description>Well, the biggest problem I have with the entire problem is that you're missing a very pressing point. You only have two balls. If you drop even one ball one floor, you're fracturing the structure of the ball, and as such, weakening it. My biggest concern wouldn't be how many tries it takes, but to test the resilience of the ball and find the maximum height at which you could drop it and have it still maintain its integrity, then convert that to 'floors high' - Great question though!</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">David B</dc:creator><pubDate>Thu, 12 Mar 2009 18:38:40 -0000</pubDate></item><item><title>Re: Interview Questions: Two Bowling Balls | 20bits</title><link>http://20bits.com/articles/interview-questions-two-bowling-balls/#comment-7149781</link><description>ohh Math .. I think its so much puzzling Question</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">sarafoster</dc:creator><pubDate>Thu, 12 Mar 2009 15:07:56 -0000</pubDate></item><item><title>Re: Interview Questions: Two Bowling Balls | 20bits</title><link>http://20bits.com/articles/interview-questions-two-bowling-balls/#comment-4135965</link><description>anyone take into account the acceleration of the ball.&lt;br&gt;&lt;br&gt;The speed of the ball is the key to when it breaks, and it goes as sqrt(h).&lt;br&gt;So one should take that into account when sampling (i.e. sample not every S floors,&lt;br&gt;but make it a uniform stride in impact velocity).&lt;br&gt;&lt;br&gt;from a physics point of view, questions are not asked to see the result, but&lt;br&gt;how one thinks about things.  Including discussions of important factors &lt;br&gt;like:&lt;br&gt;&lt;br&gt;climbing up stairs, terminal velocity, the quick solution, the optimal solution,&lt;br&gt;accumulated wear on the ball, insuring zero initial velocity, using non-integer floors&lt;br&gt;by allowing a small initial downward velocity, or tossing the ball up halfway between floors, &lt;br&gt;repeatability of the experiment, are the balls identical, why aren't the windows locked, measuring&lt;br&gt;the temperature while doing the experiment, effect of Coriolis force on the ball, etc</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">bob</dc:creator><pubDate>Tue, 02 Dec 2008 17:59:06 -0000</pubDate></item><item><title>Re: Interview Questions: Two Bowling Balls | 20bits</title><link>http://20bits.com/articles/interview-questions-two-bowling-balls/#comment-4036973</link><description>This problem is recursive in nature. Basically, if you drop a ball at floor k, and it breaks, then you reduce the problem to one less ball with floor k -1. On the other hand, if it does not break, the problem becomes the same number of balls but with floor n - k.&lt;br&gt;&lt;br&gt;So, basically this problem can be solved with dynamic programming, by optimizing this:&lt;br&gt;&lt;br&gt;F(m, n) = 1 + max(F(m-1, k-1), F(m, n-k)) for k = 1.. n&lt;br&gt;&lt;br&gt;Running this on F(2, 100) can show that 14 is indeed the optimal solution. This should be able to changed to optimize for the average case, not the worst case.&lt;br&gt;&lt;br&gt;What's interesting is that (if my program is correct) it only takes 5 balls to achieve 7 steps (which is the best possible number of steps, since 2^6 &amp;lt; 100 and 2^7 &amp;gt; 100).</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Hotball</dc:creator><pubDate>Thu, 27 Nov 2008 05:32:04 -0000</pubDate></item><item><title>Re: Interview Questions: Two Bowling Balls | 20bits</title><link>http://20bits.com/articles/interview-questions-two-bowling-balls/#comment-4032842</link><description>I'm not an engineer or a mathematician, but I am a logical sort of person with some kind of college science degree -- I've forgotten what it's in because I've never worked in the industry. &lt;br&gt;&lt;br&gt;Anyway, that aside, the problem is fundamentally flawed and I'd refuse to answer the question on those grounds (and obviously not get the job).  At any rate, I like to think out of the box, so here's some out-of-the box considerations for this problem.&lt;br&gt;&lt;br&gt;The problem must first be re-defined to make it into a legitimate problem.  Why? Any time you drop the bowling ball from any floor, you are subjecting it to forces that have the potential of breaking the ball.  Now, even though a single drop from, say, the 10th floor may not break the ball, it may cause certain internal stress on the ball (or micro-fractures) that are not visible to the naked eye, which will cause the ball to break on the next drop above 10 (let's say 14 for the sake of argument).  Thus, if you took a brand new, never-been-dropped ball and let it go from 14, not having suffered previous trauma, may stay intact, thus skewing your results.&lt;br&gt;&lt;br&gt;In order for this problem to become valid, you go over to company stores, and social-engineer them into requisitioning a box of bowling balls to be FedExed to you.  Then you can start with a baseline of 50 floors, examine the results, and whether the ball breaks or not, add or subtract floors accordingly, but ensuring to drop a fresh ball each time.  If you were to multiply or divide by a factor of 2 (or so): 50; (25 is not further divisible by 2 so let's just go ahead and descend one more floor)... 24; 12; 6; 3; 2; 1, your worst case scenario would look like this: &lt;br&gt;(B=break; I=intact). &lt;br&gt; 50(B); 24(I); 36(B); 30(I); 33(B); 32(B); 31(B).  &lt;br&gt;&lt;br&gt;If, however you are an unlucky bugger and the breaking point just happens to be 49, you might get this:&lt;br&gt;&lt;br&gt;50(B); 24(I); 36(I); 43(I); 46(I); 48(I); 49(B).  &lt;br&gt;&lt;br&gt;Either way, the answer will be 7.&lt;br&gt;&lt;br&gt;Thus, make sure your purchasing department orders 25 bowling balls.  That way you can run the experiment 3 times for consistency and to get accurate numbers.  This will use 21 of the 25 balls.  Then, you can take the remaining 4 balls, one for yourself, and 3 for the guys down in purchasing so you can take them out bowling as a "thank you" when all the BS is done!</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jim Dunlop</dc:creator><pubDate>Wed, 26 Nov 2008 20:08:40 -0000</pubDate></item><item><title>Re: Interview Questions: Two Bowling Balls | 20bits</title><link>http://20bits.com/articles/interview-questions-two-bowling-balls/#comment-4032145</link><description>Lee,&lt;br&gt;&lt;br&gt;That's not true.  What happens if the bad floor is the 10th floor?  Once the ball breaks on the 25th floor you're done.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">jfarmer</dc:creator><pubDate>Wed, 26 Nov 2008 19:15:11 -0000</pubDate></item><item><title>Re: Interview Questions: Two Bowling Balls | 20bits</title><link>http://20bits.com/articles/interview-questions-two-bowling-balls/#comment-4031937</link><description>You were on the right track at the start of "Solution 2".  The solution to this problem is obviously an application of the binsearch or binary search algorithim.  You divide each remaining half of the floors and seach in the middle of the remaining segment of floors.  As an example, if the ball breaks at the 50th floor, you go to the 25th floor for the next trial.  If it doesn't break, you go to the 75th floor.  The worst-case solution is seven bowling ball drops.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Lee</dc:creator><pubDate>Wed, 26 Nov 2008 18:57:00 -0000</pubDate></item><item><title>Re: Interview Questions: Two Bowling Balls | 20bits</title><link>http://20bits.com/articles/interview-questions-two-bowling-balls/#comment-4027064</link><description>You missed something potentially usefull.&lt;br&gt;Setting the upper limit where you can stop testing.&lt;br&gt;&lt;br&gt;Step 1 -- Calculate terminal velocity, using size and weight (for example, say thanks to wikipedia, example uses maximum weight), guesstimating drag coefficient at .47 for a smooth sphere.&lt;br&gt;&lt;br&gt;-1/2 (rho) * v^2 * A * Cd = m * g&lt;br&gt;-1/2 1.3 * v^2 * pi*(0.108)^2 * 0.47  =  7.2 * 9.81&lt;br&gt;0.0112 * v^2 = 70.6&lt;br&gt;v ~ 79.40 m/s&lt;br&gt;&lt;br&gt;Step 2 -- Determine fall distance at which terminal velocity is achieved&lt;br&gt;79.4 m/s is reached after 79.4 / 9.8 = 8.1 seconds&lt;br&gt;&lt;br&gt;d = 1/2 * g * t^2&lt;br&gt;d = 1/2 * 9.8 * 8.1^2&lt;br&gt;d = 321.65 meters&lt;br&gt;&lt;br&gt;So, depending on the dimensions of the building (and of course, the weight of the bowling ball), you can skip the top few floors. If it's a children's ball (weight 6 pounds or 2.72 kg), the max required test height is only 121 meters, or roughly 40 floors. Depending on your ball, a little physics will do wonders for the number of tests.&lt;br&gt;&lt;br&gt;With a light ball, even your Method 1 will solve the problem in 10 steps, if only you used some physics first.&lt;br&gt;You can do even better by calculating at which height the ball will break. That way, assuming you have reasonably accurate figures, you can do it in 3 or 4 tests.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Alcari</dc:creator><pubDate>Wed, 26 Nov 2008 13:17:04 -0000</pubDate></item><item><title>Re: Interview Questions: Two Bowling Balls | 20bits</title><link>http://20bits.com/articles/interview-questions-two-bowling-balls/#comment-3994207</link><description>Zing.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">jfarmer</dc:creator><pubDate>Mon, 24 Nov 2008 16:33:42 -0000</pubDate></item><item><title>Re: Interview Questions: Two Bowling Balls | 20bits</title><link>http://20bits.com/articles/interview-questions-two-bowling-balls/#comment-3993829</link><description>I don't think that word means what you think it means.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">One "Special" Guy</dc:creator><pubDate>Mon, 24 Nov 2008 16:06:04 -0000</pubDate></item><item><title>Re: Interview Questions: Two Bowling Balls | 20bits</title><link>http://20bits.com/articles/interview-questions-two-bowling-balls/#comment-3975596</link><description>I don't see why you have the equality  C + (C-1) + ... + 1 &amp;gt; N strict here. Dropping a ball at a level C gives you an inclusive upper bound in the resilience-height of the ball. &lt;br&gt;&lt;br&gt;Secondly: You ponder the existence of a better solution. Would you not be able to easily prove this is optimal? This is worst-case analysis so we can take on the role of the adversary when considering alternative algorithms.&lt;br&gt;&lt;br&gt;Clearly there exists a smallest integer C s.t. C is the lowest possible number of tries you have to make. &lt;br&gt;&lt;br&gt;Claim: &lt;br&gt;    Dropping the ball on height C in the first step is optimal. &lt;br&gt;Proof:&lt;br&gt;    If an alternative algorithm chooses to drop it lower, we just place the actual place the ball breaks higher. Then in the next step the alternative would have to solve something &amp;gt;at least&amp;lt; as hard.&lt;br&gt;    If an alternative algorithm chooses to drop it higher, then just place the ball in the last spot the algorithm would look with the remaining ball. (Remember we can be psychics when placing the ball here.) This would result in a &amp;gt;worse&amp;lt; number of tries.&lt;br&gt;&lt;br&gt;Repeating this argument in each step proves that your strategy is optimal.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ali Pang</dc:creator><pubDate>Sun, 23 Nov 2008 19:34:07 -0000</pubDate></item><item><title>Re: Interview Questions: Two Bowling Balls | 20bits</title><link>http://20bits.com/articles/interview-questions-two-bowling-balls/#comment-3961930</link><description>"You're graded on your algorithm's worst-case running time."&lt;br&gt;&lt;br&gt;Your algorithm's worst-case is 100.  His last algorithm's worst-case is 14.  A shorter running time is better, of course.&lt;br&gt;&lt;br&gt;You have the worst possible worst-case running time.  Not only did you fail, you failed as hard as you possibly could.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Kapow</dc:creator><pubDate>Sat, 22 Nov 2008 19:09:28 -0000</pubDate></item><item><title>Re: Interview Questions: Two Bowling Balls | 20bits</title><link>http://20bits.com/articles/interview-questions-two-bowling-balls/#comment-3958333</link><description>Jarrod,&lt;br&gt;&lt;br&gt;No, that wasn't the reason.  If anything it was the opposite.  The rest of my interview didn't inspire enough technical confidence, and I spent my time asking questions about their business.  Read here for the details: &lt;a href="http://20bits.com/articles/when-its-your-turn/" rel="nofollow"&gt;http://20bits.com/articles/when-its-your-turn/&lt;/a&gt;&lt;br&gt;&lt;br&gt;The reason I received for not getting an offer was that I, quote, "didn't have a strong enough technical background."</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">jfarmer</dc:creator><pubDate>Sat, 22 Nov 2008 18:04:02 -0000</pubDate></item><item><title>Re: Interview Questions: Two Bowling Balls | 20bits</title><link>http://20bits.com/articles/interview-questions-two-bowling-balls/#comment-3958120</link><description>Excellent article, very thought-provoking.&lt;br&gt;&lt;br&gt;I cannot help but wonder if, by presenting the article in story format (and not as a purely abstract mathematical problem), the interviewer was inviting you to consider real-world implications such as the damage done to each ball when dropped, terminal velocity, etc. Especially if the job was for a programmer, who'd be familiar and comfortable with more abstract problems.&lt;br&gt;&lt;br&gt;As one previous comment suggested, sometimes it's more difficult to find a programmer who understands the business rules than it is to find someone who can devise an efficient, mathematically sound algorithm. I've seen programmers spend hours and wrack their brains coming up with elegant, sophisticated "solutions" that overlook simple, common-sense factors.  No offense intended, but programmers, IT specialists, and INTP-types are sometimes guilty of dwelling on theory at the expense of practice...</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jarrod</dc:creator><pubDate>Sat, 22 Nov 2008 17:48:48 -0000</pubDate></item><item><title>Re: Interview Questions: Two Bowling Balls | 20bits</title><link>http://20bits.com/articles/interview-questions-two-bowling-balls/#comment-3956467</link><description>I outline the steps in the article.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">jfarmer</dc:creator><pubDate>Sat, 22 Nov 2008 14:43:21 -0000</pubDate></item><item><title>Re: Interview Questions: Two Bowling Balls | 20bits</title><link>http://20bits.com/articles/interview-questions-two-bowling-balls/#comment-3956446</link><description>You sound pretty anti-social.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">jfarmer</dc:creator><pubDate>Sat, 22 Nov 2008 14:40:19 -0000</pubDate></item><item><title>Re: Interview Questions: Two Bowling Balls | 20bits</title><link>http://20bits.com/articles/interview-questions-two-bowling-balls/#comment-3956442</link><description>Yer so clever! you get 4 gold stars today.  It's interesting to see all the erroneous assumptions posited here.  I give, what's the answer?</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Biff Tardisblue</dc:creator><pubDate>Sat, 22 Nov 2008 14:39:55 -0000</pubDate></item><item><title>Re: Interview Questions: Two Bowling Balls | 20bits</title><link>http://20bits.com/articles/interview-questions-two-bowling-balls/#comment-3956010</link><description>Hey Yishan,&lt;br&gt;&lt;br&gt;Thanks for the offer.  A year and a half ago I might have taken you up on that, but Facebook has changed too much and so have I.&lt;br&gt;&lt;br&gt;- Jesse</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">jfarmer</dc:creator><pubDate>Sat, 22 Nov 2008 14:19:05 -0000</pubDate></item><item><title>Re: Interview Questions: Two Bowling Balls | 20bits</title><link>http://20bits.com/articles/interview-questions-two-bowling-balls/#comment-3955791</link><description>Read here if you want to know why: &lt;a href="http://20bits.com/articles/when-its-your-turn/" rel="nofollow"&gt;http://20bits.com/articles/when-its-your-turn/&lt;/a&gt;&lt;br&gt;&lt;br&gt;I only blame myself, although in retrospect I'm glad I didn't get it.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">jfarmer</dc:creator><pubDate>Sat, 22 Nov 2008 13:52:57 -0000</pubDate></item><item><title>Re: Interview Questions: Two Bowling Balls | 20bits</title><link>http://20bits.com/articles/interview-questions-two-bowling-balls/#comment-3955766</link><description>*shrug*</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">jfarmer</dc:creator><pubDate>Sat, 22 Nov 2008 13:50:30 -0000</pubDate></item><item><title>Re: Interview Questions: Two Bowling Balls | 20bits</title><link>http://20bits.com/articles/interview-questions-two-bowling-balls/#comment-3955758</link><description>About 500 people, last count.  It was Facebook.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">jfarmer</dc:creator><pubDate>Sat, 22 Nov 2008 13:49:40 -0000</pubDate></item><item><title>Re: Interview Questions: Two Bowling Balls | 20bits</title><link>http://20bits.com/articles/interview-questions-two-bowling-balls/#comment-3955693</link><description>Meneer,&lt;br&gt;&lt;br&gt;If you read the post, the naive solution of using one ball and going one floor at a time is the first one given.  The interviewer was happy with the solution.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">jfarmer</dc:creator><pubDate>Sat, 22 Nov 2008 13:42:38 -0000</pubDate></item><item><title>Re: Interview Questions: Two Bowling Balls | 20bits</title><link>http://20bits.com/articles/interview-questions-two-bowling-balls/#comment-3955676</link><description>Not true.  You are guaranteed to find a solution by going one floor at a time with one ball.  But can you do better?</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">jfarmer</dc:creator><pubDate>Sat, 22 Nov 2008 13:40:59 -0000</pubDate></item><item><title>Re: Interview Questions: Two Bowling Balls | 20bits</title><link>http://20bits.com/articles/interview-questions-two-bowling-balls/#comment-3955278</link><description>Obviously the point of the question is to get a sense of the prospect's mathematical reasoning ability. That said, before working out algorithms, I'd expect a pragmatic programmer to ask things like:&lt;br&gt;&lt;br&gt;1. Can't he manufacturer just tell us, so we can store the value and retrieve it as needed?&lt;br&gt;2. Can we copy the bowling balls, and then use an existing binary search function?&lt;br&gt;3. Has anyone else done this? Is there a library that we can use?&lt;br&gt;4. Etc ...&lt;br&gt;&lt;br&gt;In other words, how can we avoid having to solve the problem ourselves if we don't have to?&lt;br&gt;&lt;br&gt;Cheers, Rick</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Rick Spencer</dc:creator><pubDate>Sat, 22 Nov 2008 13:03:49 -0000</pubDate></item><item><title>Re: Interview Questions: Two Bowling Balls | 20bits</title><link>http://20bits.com/articles/interview-questions-two-bowling-balls/#comment-3954315</link><description>If you only have two balls, probability will prevent you from completing any of these prosposed solutions, as both balls will be destroyed before the answer is found.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Biff Tardisblue</dc:creator><pubDate>Sat, 22 Nov 2008 11:35:52 -0000</pubDate></item></channel></rss>