## American Airlines Interview Question for Software Engineer / Developers

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

Two.

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.
or
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.

??LLLLLL

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.

HHHLLLLL

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.

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

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

Comment hidden because of low score. Click to expand.
0
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.

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

two

Name:

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

### Books

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

### Videos

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.