A Googlish puzzle
It’s probably getting to the point where everyone’s a bit tired of hearing about Google’s interview process but recently heard a nice one someone was given to solve – one of those “Can you think like a programmer?” type questions. It goes like this…
You have two eggs. These are special eggs – they can take much more punishment than you average chicken egg. But the question is 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?
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.
Technically there isn’t a “right” answer as such, although what was expected is an approach that requires the least number of tests, irrespective of where the result lies – an efficient search algorithm which offers consistent performance no matter what the result is. If you’re struggling for inspiration, try here – doesn’t help directly but might prompt some lateral thought.
To some extent questions like this are a little unfair these days, if it wasn’t Google doing the asking. Picking a random number, I’d guess 95% of programming today has nothing to do with solving these kind of problems any more – it’s all hidden behind APIs (or in DBs) offering “good enough” performance 99+% of the time. Most employers will be less-than-impressed if your answer to “Is it finished yet?” is “No, but my latest search algorithm is kicking”.
Anyway – something not-too-heavy to ponder over while waiting for the whistle.