American Airlines Interview Question for Software Engineer / Developers

Comment hidden because of low score. Click to expand.
of 0 vote


It's easiest to think about this in terms of cases. In addition, I'll use notation for the balls such that ? represents a ball whose weight you don't have any idea about, H represents a ball that could be heavy, and L represents a ball you know to be light. When you begin, you have eight balls, none of which you know the weight of.


First, you take six of those balls, and weigh them, three on each side. Then either:
1) One of the sides is heavier.
2) Neither of the sides are heavier.

In case 2, you know that six of the balls are not the heavy ball. You don't know about the other two.


You then take one of the ? balls, and weigh it against one of the L balls. Again there are two possible outcomes:
2.1) The ? ball is heavier.
2.2) The balls are the same.

In case 2.1, we know that the ? ball we just weighed must be the heavy ball, because it's heavier than a ball we know to be normal. In case 2.2, we know that the ? ball we *did not weigh* must be the heavier ball, because we know all other balls to be light.

Now let's jump back to case 1. In this case, three of the balls we weighed could be the heavy ball; the rest must be light.


Our next weighing has one of the H balls against another H ball. This time, there are three ways the weighing could turn out:
1.1) The first H ball is heavier.
1.2) The second H ball is heavier.
1.3) The balls weigh the same.

In cases 1.1 and 1.2, we now know which of the balls is heaver. In case 1.3, the two balls we weighed must be light, because there's only one heavy ball; thus, there is only one possibly heavy ball remaining, so that ball must be the heavy ball.

- Nex3 December 07, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 votes

it will need 3 shots.. log 8 (base 2)

- Anonymous March 07, 2008 | Flag
Comment hidden because of low score. Click to expand.
of 0 vote

Will take only 2 shots. First shot compare pair of 3 balls 1233 with 456. If they are not same lets say 123 is heavier then way 1 and 2 if they are same 3 is heavier. If 123 and 456 are same then weight 7 and 8 and find out which one is heavier. So total trial required only 2.

- gauravk.18 April 01, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote


- bhikshu2002 April 15, 2009 | Flag Reply

Add a Comment

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.


is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More


CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More