Google is also known for its interesting interview questions. ±¸±ÛÀº ¶ÇÇÑ Èï¹Ì·Î¿î ÀÎÅͺä Áú¹® À¯¸íÇÕ´Ï´Ù. Enjoy this one and my solution. Çϳª¿Í ³» ¼Ö·ç¼ÇÀ» Áñ±æ ¼öÀÖ½À´Ï´Ù. Suppose you have two eggs. °¡Á¤ °è¶õÀÌ µÎ °³ÀÖ½À´Ï´Ù. These are special eggs—they can take much more punishment than you average chicken egg. À̵éÀº ó¹úÀ» Ưº° °è¶õ - ±×µéÀº ´ç½Åº¸´Ù ÈξÀ ´õ °É¸± ¼öÀÖ½À´Ï´Ù Æò±Õ ´ß°í±â °è¶õÀ»ÇÕ´Ï´Ù. The question is exactly just how much punishment can they take? ¹®Á¦´Â Á¤È®ÇÏ°Ô ´ÜÁö ó¹úÀ» ÇÒ ¼ö ¾ó¸¶³ª °É¸±±î¿ä?


Using a 100 storey building and only the two eggs, how would you find out which is the highest floor of the building you can drop the eggs from, before they break? 100 Ãþ °Ç¹°°ú¸¸À» »ç¿ëÇÏ¿© µÎ °³ÀÇ ³­ÀÚ°¡ ¾î¶»°Ô ¾Ë¾Æ ³Â Ãþ °Ç¹°ÀÌ ÃÖ°íÀÇ °è¶õÀ»ÇÏ½Ç ¼öÀÖ½À´Ï´Ù¿¡¼­ µå·ÓÇϱâ Àü¿¡, ±×µéÀº ÈÞ½Ä ½Ã°£?

It could be the 1st floor but it could also be the 99th floor—you don¡¯t know but to test, you need to try dropping the eggs from different floors and see what happens. ±×°Í ¼öÀÖ´Â 1 ÃþÇÏÁö¸¸ÀÌ 99¹øÂ° ¼öµµÀÖ½À´Ï´Ù Ãþ - ³Í ¸ð¸£Áö¸¸ »õ ¹öÀüÀ» Å×½ºÆ®ÇÏ·Á¸é ¶³¾îÁö´Â °è¶õÀ» ½ÃµµÇؾßÇÕ´Ï´Ù ¼­·Î ´Ù¸¥Áö¸é, ¾î¶»°ÔµÇ´ÂÁöÇÕ´Ï´Ù.

via SitePoint ¸¦ ÅëÇØ Sitepoint -

Are you done yet? ¾ÆÁ÷µµ ¸Ö¾ú¼Ò? My solution is simple. ³» ÇØ°áÃ¥Àº °£´ÜÇÕ´Ï´Ù.
Use binary search with one egg till it breaks. ÀÌÁø °Ë»ö°ú Çϳª°¡ µÉ¶§±îÁö °è¶õ ³ª´©±â¸¦ »ç¿ëÇÕ´Ï´Ù. Use linear search with the second egg till it breaks. ¼±Çü °Ë»öÀ» »ç¿ëÇÒ ¶§±î ÁöÀÇ µÎ ¹øÂ° °è¶õ ³ª´©±âÇÕ´Ï´Ù. And you have the solution. ±×¸®°í ´ç½ÅÀºÀÌ ¼Ö·ç¼ÇÇÕ´Ï´Ù. If that's not clear enough allow me to explain. ¸¸¾à ±×°Ô Á¦°Ô ±âȸ¸¦ ÃæºÐÈ÷ ¼³¸íÇÒ ¸íÈ®ÇÏÁö ¾Ê´Ù.

First drop one egg from 50th (midway). ÇÑ °è¶õ¿¡¼­ ù ¹øÂ° µå·Ó 50 (¹Ìµå¿þÀÌ).

  • If it breaks (no more binary search) then drop the second egg from first floor. ¸¸¾à ºê·¹ÀÌÅ© (´õ ÀÌ»ó ÀÌÁø °Ë»ö)À» µå·Ó µÎ ¹øÂ° °è¶õÀ» 1 Ãþ¿¡ÀÖ½À´Ï´Ù. Move up one floor at a time till it breaks. ÇÑ ¹ø¿¡ ÇÑ Ãþ À§·Î À̵¿ÇÒ ¶§±î ÁöÀÇ ÈÞ½ÄÇÕ´Ï´Ù.
  • If it doesn't break then drop it from 75th floor. ÈÞ½Ä ½Ã°£À» ¶³¾î¶ß¿¡¼­ÇÏÁö ¾ÊÀ¸¸é 75 ÃþÇÕ´Ï´Ù.
    • If it breaks then drop the second egg from 76th floor. ¸¸¾à ºê·¹ÀÌÅ©¸¦ µå·Ó 76¹øÂ° ¹Ù´Ú¿¡¼­ µÎ ¹øÂ° °è¶õÀ»ÇÕ´Ï´Ù. Move up one floor at a time till it breaks. ÇÑ ¹ø¿¡ ÇÑ Ãþ À§·Î À̵¿ÇÒ ¶§±î ÁöÀÇ ÈÞ½ÄÇÕ´Ï´Ù.
    • If it doesn't break then drop it from the 87th floor¡¦ ÈÞ½Ä ½Ã°£À» ¶³¾î¶ßÇÏÁö ¾ÊÀ¸¸é Á¦ 87 ȸ ¹Ù´Ú¿¡¼­¡¦

I hope you get the picture by now. ³ª´Â Áö±Ý±îÁö ±×¸²ÀÌ ±×·ÁÁö ¹Ù¶ø´Ï´Ù. I would love to see anyone coming with a better optimized solution. ³ª´Â »ç¶ûÀ» º¸ÀÌ´Â »ç¶÷ÀÌ Àú¿Í ÇÔ²² ´õ ³ªÀº ÃÖÀûÀÇ ¼Ö·ç¼ÇÀ»ÇÕ´Ï´Ù.

Update: The optimization is to minimize the number of drops. ¾÷µ¥ÀÌÆ® :ÀÇ ÃÖÀûÈ­´Â »óǰÀÇ °³¼ö¸¦ ÃÖ¼ÒÈ­ÇÕ´Ï´Ù.