# A Box of Defective Balls

Question: You have 10 boxes of balls (each ball weighing exactly10 gm) with one box with defective balls (each one of the defective balls weigh 9 gm). You are given an electronic weighing machine and only one chance at it. How will find out which box has the defective balls?

Answer: For convenience sake, let’s name the boxes from 1 to 10. In order to solve this problem, you have to leverage the fact that you know exactly what each good ball is supposed to weigh and what each defective ball is supposed to weigh. Many of us instinctively will take one ball out of each box and try to find a way to make it work but the trick to take different number of balls from each box.

The number of balls you pick from each bag is equal to the box number. For example, pick 1 ball from box 1, 2 balls from box 2 and so on. In total you will have 55 balls. If all of the boxes have good balls, then the total weight of these balls would be 550gm.

If box 1 has defective balls, then the total weight should be 1gm less than expected (only one ball weighing 9 gm). If box 2 has defective balls, then the total weight should be 2gm less than expected (two balls weighing 9 gm). So once you weigh the set of chosen balls, find out the difference between the total weight and the expected weight. That number represents the box number which contains the defective balls.

If you like puzzles with balls and balances, you might like 8 Identical balls problem

If you have any questions, please feel free to send me an email at [email protected]. If you have any interview questions which you feel would benefit others, I would love to hear about it.

If you're looking for some serious preparation for your interviews, I'd recommend this book written by a lead Google interviewer. It has 189 programming questions and solutions:  ## 13 Responses

1. Dan says:

Management should be fired. Why only one opportunity? The correct answer is inefficient and time consuming. The best answer is to weigh the boxes individually. Fast and easy. Only management would make us do it in one step.

2. A2theYo says:

The question should define “one chance at it.” My solution was to stack the boxes on top of each other and measure the difference in weight added with each box. The box with defective balls will add less weight than the others.

3. David o says:

Why would you box and unlabel defective balls fire the moron who screwed up.

4. Aditya says:

Put all the boxes on weighting machine… Then remove each box one by one from weighting machine… You will get defective ball

5. raj says:

U can simply dip both the boxes into water … Since defective ball have different weight as compared to non defective ….. So both displaces different quantities of water … By this we can find out

6. Siva sankar says:

for example If you have chosen box no 9 and the weight of the box is not equal to the expected weight .So the answer is box no 9 upto now ok..
But if in case the selected box weight is equal to the expected weight and your one chance is over then how can you say the defective box..your chances are no longer existed because your one chance is over…
Can you explain me this scenario..

7. Whatsapp Jokes says:

The question doesnot mention how many balls are there in the boxes initially.

8. Mahen says:

Question is not complete:
It should include that how many balls in each box.
if we can take out balls and label them 1,2,3

9. babul says:

the qus lacks clarity

10. Yusuf says:

What if there is only ONE defective ball among all the ten boxes?

How do go about finding out that one guy?

11. manful says:

What if each of the boxes contains less than 10 balls?

12. Akshitha says:

awesome

13. Candy says:

The question is wrongly asked, you should have said that we are allowed to take the balls out of the boxes !!!!!!!!

XHTML: These are some of the tags you can use: `<a href=""> <b> <blockquote> <code> <em> <i> <strike> <strong>`