During a technical job interview, you might be asked to solve a tricky question to prove your ability to think about a seemly impossible problem and use logic to solve the brain teaser. In this article by Eugene Kim, we get a few examples of these types of questions.
Q: Software engineer at Facebook: “You have two lightbulbs at a 100-story building. You want to find the floor at which the bulbs will break when dropped. Find the floor using the least number of drops.”
A: “Start moving up in increments of 10 floors and dropping the bulb until it breaks (ie: drop from floor 10, if it doesn’t break, drop from floor 20, etc.). Once the bulb breaks, move down to the floor before it broke on and start moving up floors in increments of one until the second bulb breaks. This results in a worst case scenario of 19 drops.”
“19 drops is not the best worst case scenario… imagine trying floor 16, if it breaks, you try 1 – 15 and thats 16 tries. If it doesn’t break, then try floor 31 and if it breaks, then try 17 – 30 (so 16 tries, including the try on floor 16). And on and on (45, 58, 70, 81, 91, 100). If you reach 91, you’ll have tried 7 floors so far and if it doesn’t break, then there’s 9 more tries to get to 100 (thus 16 in the worst case).”
Q: Software engineer at Raytheon: “In front of you are three light switches. Only one does anything, and it turns on the light downstairs. From here you can’t see the light, and it makes no sound. You must determine which switch operates the light, BUT you can only go check it once. How do you figure out which switch is for the light?”
A: “Flip any switch you want. Wait for about 5-10 minutes to let the bulb heat up. Flip that same switch off, and another one on. Go check the light. If it’s off and hot, it was the first switch, if it’s on it was the second and if it’s cold and off, it was the last one.”