REI Systems Interview Question: Unexpected question - Guess t... | Glassdoor

Interview Question

Software Engineer Interview Herndon, VA

Unexpected question - Guess the number I am thinking of

  which is between 1 and 100 by asking minimal Yes or No questions.

Interview Answer

2 Answers


Binary search algorithm, keep cutting problem in half. (Assuming it is an integer) I can do it in 7 questions. Let's say the number is 1, what is the longest it would take me dividing in half? Is it Greater than 50(n), > 25(n), > 12(n), >6(n) >3(n), so not it is 1,2,3..
is it 3 (n), is it 2(n), then it is one. 7 questions. (still works if you ask 12.5 rather than 12)

Now if you want to impress the computer guy ask your questions in true binary. The 7th bit is worth 64, so only 7 bits need to be used to count to one hundred. Ask what each of the seven bits is set to, write them down and then add it up. (yes/no question, if this number was represented in binary, is first bit a 1).

So I did not think of this last answer until after I had thought out the first, then I thought it would be a funny joke to ask him in binary, then I realized it would actually work. That is the kind of think-out-loud thought process an interview wants to see.

PuddinHead on Mar 17, 2010

One or more comments have been removed.
Please see our Community Guidelines or Terms of Service for more information.

Add Answers or Comments

To comment on this, Sign In or Sign Up.