Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Richard Damon <news.x.richarddamon@xoxy.net> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Hardest Google Interview Question |
| Date | 2011-10-23 11:48 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <j81cvn$lit$1@dont-email.me> (permalink) |
| References | <006ca4a6-1efa-4cb5-905b-91dee8c80afc@s35g2000pra.googlegroups.com> <0eaed2b5-62dc-4890-8488-eec083ca0470@fk25g2000vbb.googlegroups.com> <slrnja7lgb.9b.willem@toad.stack.nl> <54ca53b0-ab74-41c2-ab05-d1f605928082@a12g2000vbz.googlegroups.com> <slrnja7o80.74s.willem@toad.stack.nl> |
On 10/23/11 5:40 AM, Willem wrote: > Malcolm McLean wrote: > ) On Oct 23, 10:53?am, Willem<wil...@toad.stack.nl> wrote: > )> Malcolm McLean wrote: > )> > )> ) On Oct 23, 8:39?am, divya bisht<bisht88.di...@gmail.com> wrote: > )> )> Hardest Google Interview Question > )> )> > )> )>http://hardest-puzzle.blogspot.com/2011/10/google-interview-question.... > )> )> > )> ) Drop from first floor. If it doesn't break, pick up the egg, and try > )> ) the second floor, and so on. When it breaks, you know the critical > )> ) floor. > )> > )> If this is the puzzle I think it is, you're supposed to have two eggs, and > )> the question is to determine the minimal number of drops which guarantees > )> an answer. > )> > ) The obvious method is a binary search. However you are only allowed to > ) break a maximum of two eggs, and you have 100 floors to search, so it > ) won't work. > > The obvious method with 2 eggs is to use the first egg in increments of 10 > floors until it breaks, and then use the second on the 10-floor interval > below the floor where the first one broke. 19 drops worst case, IICC. > > But you can do better than that. > > > SaSW, Willem These sort of questions aren't really all that great for interviews, as they are the sort of thing that if you have seen this particular one before, it becomes trivial, if not, it requires a bit of thought, and the pause to do that becomes unnatural in the interview. They much more test how the interviewee handles being flustered under pressure than problem solving. Unless you are interviewing for something like tech support where your expect them to be hit with weird questions as part of their line of work, they aren't that good of a measure. As to this particular one, the key is to turn the problem around a bit. If we ask how tall of a building can we measure with n drops and m broken eggs. If we are only allowed to break 1 egg, then the only way to solve it is to start at the lowest floor and keep moving up, until we break, and thus we can measure an n story building. If we are allowed to break 2 eggs, then we can say that for the first drop, assuming it breaks, we have n-1 drops left, so by above we could measure n-1 floor below, so if we drop from the n story, and it break, we can use our second allowed break to figure out which floor it would happen at. If it doesn't, then we have n-1 drop left, and by the same logic we can go up n-1 more stories, to floor n+(n-1) for this drop. Continuing on, we eventually get to the floor n+(n-1)(n-2)...+1 which is known to be floor n*(n+1)/2 (the formula for triangle numbers) we can then extend this to breaking 3 eggs, and we will end up sequencing on the pyramid numbers (the sum of triangle numbers), but this is beyond what we need to do for this problem. Since we have a 100 story building, this requires an n of at least 14. So we drop the first egg from floor 14, if it doesn't break the next from floor 27, then 35, 46, ... and when we break an egg, you start from the floor above which you last didn't break and move up. Of course, the real flaw with the problem is it assumes something that is unlikely, that both eggs would have broken from exactly the same height, and that drops from a lower height don't affect the height that the egg can stand before it does break. If you don't make these unwarranted assumptions I don't think it is possible to find a solution.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Hardest Google Interview Question Malcolm McLean <malcolm.mclean5@btinternet.com> - 2011-10-23 00:02 -0700
Re: Hardest Google Interview Question Willem <willem@toad.stack.nl> - 2011-10-23 08:53 +0000
Re: Hardest Google Interview Question Malcolm McLean <malcolm.mclean5@btinternet.com> - 2011-10-23 02:21 -0700
Re: Hardest Google Interview Question Willem <willem@toad.stack.nl> - 2011-10-23 09:40 +0000
Re: Hardest Google Interview Question Richard Damon <news.x.richarddamon@xoxy.net> - 2011-10-23 11:48 -0400
Re: Hardest Google Interview Question arnuld <sunrise@invalid.address> - 2011-10-25 05:26 +0000
Re: Hardest Google Interview Question Mark Bluemel <mark_bluemel@pobox.com> - 2011-10-25 08:52 +0100
Re: Hardest Google Interview Question falk@rahul.net (Edward A. Falk) - 2011-10-25 19:47 +0000
Re: Hardest Google Interview Question Sjouke Burry <b@p.nl> - 2011-10-26 22:51 +0000
csiph-web