面试中,为了考察应聘者的思维方式,面试官偶尔会出一些谜题(Puzzles)。
比如,在谷歌,就有这样一道让人“闻风丧胆”的面试题:
You work in a 100 floor building and you get 2 identical eggs.
You need to figure out the highest floor an egg can be dropped without breaking.
The question is how many throws you need to make.
Find an algorithm that is minimizing number of throws in the worst-case scenario.
这道题的意思大致如下:
情景假设
你在一个100层高的大楼里
你有2个一模一样的鸡蛋
任务
弄清楚:鸡蛋最高可以从几层楼扔下去而不会被摔坏
弄清楚你需要扔几次
提出一个算法,找出在最坏情况下,扔出鸡蛋而不把鸡蛋摔坏的最少次数
好在近日,一位来自Gamekit的Senior Android Developer,在网上分享了他的解法。
对去Google工作感兴趣的小伙伴们,就赶紧来看看他是怎么说的吧:
首先,在解题之前,我们要做好几个简单的假设:
2个鸡蛋的脆弱程度是一样的。