Google is also known for its interesting interview questions. Google es también conocido por sus interesantes preguntas. Enjoy this one and my solution. Disfruta de este y mi solución. Suppose you have two eggs. Suponiendo que tiene dos huevos. These are special eggs—they can take much more punishment than you average chicken egg. Estos huevos son especiales-que pueden tomar mucho más la pena que le promedio de huevos de pollo. The question is exactly just how much punishment can they take? La cuestión es exactamente cuánto castigo que puede tener?


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? El uso de un edificio de 100 pisos y sólo los dos huevos, ¿cómo saber cuál es el más alto piso del edificio puedes colocar el de los huevos, antes de que?

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. Podría ser la 1 ª planta, pero también podría ser la 99 ª piso-que no conoces pero a prueba, tiene que intentar dejar caer los huevos de diferentes pisos y ver qué pasa.

via SitePoint a través de SitePoint

Are you done yet? ¿Está hecho? My solution is simple. Mi solución es simple.
Use binary search with one egg till it breaks. Utilice búsqueda binaria con un huevo hasta que se rompe. Use linear search with the second egg till it breaks. Uso de búsqueda lineal con el segundo huevo hasta que se rompe. And you have the solution. Y usted tiene la solución. If that’s not clear enough allow me to explain. Si eso no es lo suficientemente claro para permitir que me explique.

First drop one egg from 50th (midway). Primera caída de un huevo de 50 (a mitad de camino).

  • If it breaks (no more binary search) then drop the second egg from first floor. Si se rompe (no más búsqueda binaria) y luego soltar el segundo huevo de primer piso. Move up one floor at a time till it breaks. Mover hacia arriba un piso en un tiempo hasta que se rompe.
  • If it doesn’t break then drop it from 75th floor. Si no es así entonces romper descenso de 75o piso.
    • If it breaks then drop the second egg from 76th floor. Si se rompe luego soltar el segundo huevo de 76o piso. Move up one floor at a time till it breaks. Mover hacia arriba un piso en un tiempo hasta que se rompe.
    • If it doesn’t break then drop it from the 87th floor… Si no es así romper luego dejarlo caer, de la 87 ª piso…

I hope you get the picture by now. Espero que usted obtiene la imagen de ahora. I would love to see anyone coming with a better optimized solution. Me encantaría ver a alguien que viene con una mejor solución optimizada.

Update: The optimization is to minimize the number of drops. Actualización: La optimización es reducir al mínimo el número de gotas.