Interview Question: Socks

Sample Question #262 (brainteaser)
 
[This is a classic brainteaser question]
 
You get up in the wee hours of the morning and it’s still dark outside. You’re too lazy to turn on the lights and you can’t see a thing, but you open a drawer where you keep your socks. You have 10 red socks, 10 blue socks, 10 white socks, and 10 black socks, but they’re all mixed up in the drawer.
 
How many socks in the minimum do you need to take out of the drawer to ensure you get at least one pairing?
Advertisements
This entry was posted in Sample Qs. Bookmark the permalink.

4 Responses to Interview Question: Socks

  1. Brett says:

    ANSWER
     
    Since there are 4 colors, you just take out 5 stocks to ensure you get at least one pair of the same color.
     
    Bonus question: what if the number of socks of each color are different, say, 10 red socks, 2 blue socks, 5 white socks, and 30 black socks. Would the answer be the same?
     
    [This question is almost always asked with an equal number of socks for each color.]
     

  2. Monad says:

    Maybe it will be helpful to mention that this is related to the pigeonhole principle. If you have n pigeons in m holes where n>m, there is at least one hole with more than one pigeon. By analogy the total number of socks is n and the number of colors is m. One needs to pick at least m+1 socks to ensure at least a pair of the same color.

  3. Brett says:

    Monad, you’re absolutely right, this is an application of the pigeon hole principle.
    -brett

  4. Yanis Ps. says:

    Quant Career:usually there’s a left and a right sock. At least mine come this way (you can look carefully at a brand new pair of sock). Which means the answer is 21. Q.E.D. -Yanis

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s