This is the third of perhaps many written about questions traditionally asked at job interviews. I think it’s their indefiniteness that I love so much — its companies acknowledging that their problems are just applied brainteasers so try to gauge how good you are at brainteasers. Awesome.

This question comes a Google interview. It goes like this:

You have a black box called “Function Alpha”. Every time you call Function Alpha it returns A or B with a 1/2 probability for each. You are to write something that uses Function Alpha that and gives you “Function Beta”: which returns A two thirds of the time and B the other third. How do you do this?

Hit the link to see the full solution

Call Alpha twice. If you get B/B then you return B for function Beta. If your results from Alpha are A/B or B/A then you return A for Beta. And finally if you got A/A you call this function again. This is the “correct” answer according to the proctor. Do you have an alternate solution though?