Interview Logic Question

  • LOGIC PROBLEM -- There are three boxes. One labeled “Nickels” another “Quarters” another “Nickels and Quarters”. They are all mislabeled. How could you select ONE item from ONE box and figure out how to relabel the boxes correctly.

    Please help to solve this Logic Problem.

  • enthuse0809 (8/11/2012)


    LOGIC PROBLEM -- There are three boxes. One labeled “Nickels” another “Quarters” another “Nickels and Quarters”. They are all mislabeled. How could you select ONE item from ONE box and figure out how to relabel the boxes correctly.

    Please help to solve this Logic Problem.

    This question tests for two things. Of course, it tests for logic/problem solving but it also tests your ability to listen correctly.

    The key to solving this problem is the knowledge that [font="Arial Black"]ALL [/font]of the boxes are mislabeled. If you miss that or forget that or simply don't include it in your thinking, the problem is impossible to solve. Let's see what this does for us. I used abbrevations for the Nickels (N), Quarters (Q) and Nickels/Quarters (C for combined).

    Box

    N <--- You chose this box and you pull a Nickle.

    Q

    C

    In the above scenario and since ALL of the boxes are mislabeled, THIS CANNOT BE THE N box. It HAS to be the C box because I just pulled an N from the incorrectly labeled N box. Obviously, it can't be the Q box.

    So you remove the N label from the box and move the C label to the box. One down, two to go.

    Since ALL the boxes are mislabeled, the Q box is, by definition, mislabeled. Since you just proved the current box is the C box, you simply move the label from the Q box to what used to be the C box.

    Now the old Q box is missing a label and, of course, the only possibility left is the label that isn't currently attached to any box. The N label. Attach it to what used to be the Q box and you're done.

    Let's try the same thing by by pulling a coin from the box labeled C...

    N

    Q

    C <--- You chose this box and you pull a Nickle.

    First, by definition, the box label C cannot be C because all of the labels are defined as being incorrect. So the box label C must be either an N or a Q box. You pull a nickle from the box which confirms that it's the N box. You remove the label from C and replace it with the label from N.

    Since, by definition, all of the boxes are mislabeled, The Q label cannot be on the real Q box and you just proved the box you just labeled N really is the N box. So you just move the label from the Q box to the old N box and then put the C label on the old Q box and you're done.

    The same type of logic prevails no matter which box you pick and no matter which coin you pick. Again, the key to the problem is that ALL of the boxes have been mislabeled by definition. Then, using a bit of "negative" logic easily tells you where the labels need to go to be correct.

    Shifting gears, I think that asking questions like this on an interview is absolutely ridiculous. Anyone serious about landing a programming job will have a good amount of logic to back them up even if they can't solve such a problem in under 10 minutes (except those looking for "Google quality" programmers and most aren't). If the interviewers have a wad of such "logic" questions that the interviewee can't answer, they might still be missing out on a proverbial "work horse" that can churn good code out with the best of them.

    If, as with so many other things, the interviewee is expecting such questions (and there's no reason not to), a day or two in front of "Google" searching for "Wierd interview questions" will allow the interviewee to memorize more such trivial "logic" questions than the interviewer could probably come up with. That would give the interviewer the false sense that the interviewee had some form of extraordinary logic abilities and hire the wrong person.

    I had someone ask me this question during an interview, once. I hadn't heard the question before and quickly came up with the answer but I was incensed that such a ridiculous question was asked. So, instead of answering the question, I made them get me 3 empty waste baskets, 3 post-it notes, and a magic-marker. I carefully labeled all 3 and made them watch as I loaded each waste backet with the appropriate incorrect coins from my pocket. I started to explain by seemingly pulling a coin out of one of the mislabeled waste baskets. What they didn't know is that I had palmed a dime and "pulled" that out of the basket, smiled, said that the people who gave the requirements gave some lousy requirements because it had no plans for error handling, flipped the dime to the lead interviewer, and then walked out of the interview.

    The expressions on their faces was certainly worth the 70 cents I left behind.

    {EDIT: Grammer and punctuation correction.}

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Pick your one item from box labeled [N and Q]. Let's say you pull nickel. So, this is [N] box. Swap labels with box that have [N] label. Then swap [N and Q] with

    box.

    Same thing if you you pull Q first time.

    Do you want T_SQL for that too? 😀

    Edit for clarity.

    --Vadim R.

  • Jeff Moden (8/11/2012)


    I had someone ask me this question during an interview, once. I hadn't heard the question before and quickly came up with the answer but I was incensed that such a ridiculous question was asked. So, instead of answering the question, I made them get me 3 empty waste baskets, 3 post-it notes, and a magic-marker. I carefully labeled all 3 and made them watch as I loaded each waste backet with the appropriate incorrect coins from my pocket. I started to explain by seemingly pulling a coin out of one of the mislabeled waste baskets. What they didn't know is that I had palmed a dime and "pulled" that out of the basket, smiled, said that the people who gave the requirements gave some lousy requirements, had no plans for error checking, and then walked out of the interview.

    :-D:-D:-D

    I didn't know about this question before. But couple of years ago in one online interview there was a question about "three doors" as I called it back then. It was, of course the Monty Hall problem. I couldn't come up with "theoretical" answer and ended up writing VB6 code to solve it.

    --Vadim R.

  • rVadim, Thank you for posting about the Monty Hall problem. I had not heard of this one in any of its various names but I'm always fascinated by logic problems.

  • Thank you All for the answer. It is clear to me now.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply