Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Problem Statement
3.
Approach
4.
Frequently Asked Questions
4.1.
What are puzzles?
4.2.
What are the advantages of solving puzzles?
4.3.
What is the minimum number of times he has to draw socks to go out for school for ten black socks and ten white socks?
4.4.
What would be the answer to the question if there were ten black socks and only one white sock?
4.5.
What would be the answer to the question if there were ten black, ten white and ten red socks?
5.
Conclusion
Last Updated: Mar 27, 2024
Easy

Ten Black and Ten White Socks

Author HET FADIA
0 upvote
Interview Puzzles

Introduction

A puzzle is a toy, game, or problem that trains our brain. A puzzle helps us develop problem-solving skills and perseverance. In this article, we will solve a puzzle based on socks.

Problem Statement

A boy has ten black socks and ten white socks in his drawer. As he wants to go out to school, he needs to wear a pair of socks of the same color. He draws his socks one by one without replacement and without looking in his drawer. What is the maximum number of times he has to draw socks to go out for school?

Approach

Let us denote B for the black sock and W for the white sock.

The boy needs to take out at least two socks to find a pair of socks. A pair of socks taken out may contain one of the following: (B, B), (B, W), (W, W) and (W, B).

(B, B) and (W, W) are valid as they form the pair of the same colors of socks. But the other two are not valid.

When the boy takes out the third sock, the pairs may contain one of the following:

(W, W, W)

(W, W, B)

(W, B, W)

(W, B, B)

(B, W, W)

(B, W, B)

(B, B, W)

(B, B, B)

Now each one of them has a pair of Black or White socks, as seen below:

(W, W, W) has a pair of W socks

(W, W, B) has a pair of W socks

(W, B, W) has a pair of W socks

(W, B, B) has a pair of B socks

(B, W, W) has a pair of W socks

(B, W, B) has a pair of B socks

(B, B, W) has a pair of B socks

(B, B, B) has a pair of B socks

Thus the minimum number of socks the boy has to draw from his drawer is 3.

Check out this problem - 8 Queens Problem

Frequently Asked Questions

What are puzzles?

A puzzle is a game or problem that trains our brain.

What are the advantages of solving puzzles?

Puzzles train our brains and help us develop problem-solving skills.

What is the minimum number of times he has to draw socks to go out for school for ten black socks and ten white socks?

He has to draw a minimum of two socks to find a pair of socks of the same color. For example, he can draw a pair of Black socks or a pair of white socks.

What would be the answer to the question if there were ten black socks and only one white sock?

The answer would still remain 3. When he takes three socks out, he will always get one pair of black socks.

What would be the answer to the question if there were ten black, ten white and ten red socks?

The answer is 4. Whenever he takes four socks out, he will always get a pair of socks of the same color.

Conclusion

We have extensively discussed the answer to the puzzle, Ten Black and Ten White Socks.

Logical Puzzles:


Pattern Based Puzzles:


Recommended Readings:


Do check out The Interview guide for Product Based Companies as well as some of the Popular Interview Problems from Top companies like Amazon, Adobe, Google, etc. on Coding Ninjas Studio.

Also check out some of the Guided Paths on topics such as Interview Puzzles, Data Structure and Algorithms, Competitive Programming, Operating Systems, Computer Networks, etc. as well as some Contests, Test Series, Interview Bundles, and some Interview Experiences curated by top Industry Experts only on Coding Ninjas Studio.

Live masterclass