## Amazon Interview Question for Software Engineer / Developers

• 1
of 1 vote

Country: United States
Interview Type: Written Test

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

I can win the first challenge with 50% probability:

``P = (3!/2! + 1)/2^3 = 0.5``

And the second one with 36% probability:

``P = (8!/7! + 8!/2*6! + 8!/3*5! + 1)/2^8 ≈ 0.363``

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

You forgot a factor of 2 in the 8!/3*5! term it should instead be 8!/(3!*5!). Your numerical answer is correct though.

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

Can someone tell me why is there a '1' in the numerator (3!/2! + 1)/2^3.
I thought is should just (3!/2!)/2^3

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

urgh never mind I got it. Dumb me. We need to add all slams possible too as 1

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

This is based on the assumption that the prob of the player having a basket is 1/2. A more general form would be to assume that's p.
Then P(winning 1) = C(3,2)*p^2*(1-p) + C(3,3)*p^3
P(winning 2) = C(8,5)*p^5*(1-p)^3 + C(8,6)..... + C(8,7).... + C(8,8)...
(you get the idea)

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

I would say the second challenge.

The first challenge requires you to make it 66% of the time while the second challenge only requires you to make it 63%. The drop of 3% might be significant.

Also, the condition for independence between shoot is questionable. As you try 8 times, you have more practices and might be able to make it into the basket in the subsequent throws. Therefore, the option of trying 8 times might mean better chance of winning the game.

That's what I think from my statistics perspective.

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

Using Binomial Coefficient When taking 8 attempts:
Challenge 1: C(3,2) * C(3,2) * C(2,1) = 18
Challenge 2: C(8,5) =56

Since there are 56 ways to score 5 out of 8 in challenge 2 scheme compared to 18 ways to score 5 out of 8 in challenge one scheme, challenge two is a better choice.

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

Amount of ways to win challenge 1:

``C(3, 2) + C(3, 3)``

, amount of ways to lose challenge 1:

``C(3, 0) + C(3, 1)``

. But

``C(n, k) === C(n, n-k)``

, so

``C(3, 2) === C(3, 1), C(3, 0) === C(3, 3)``

.

Amount of ways to win challenge 2:

``C(8, 5) + C(8, 6) + C(8, 7) + C(8, 8)``

and amount of ways to lose challenge 2:

``C(8, 0) + C(8, 1) + C(8, 2) + C(8, 3) + C(8, 4)``

, but

``C(8, 8) === C(8, 0), C(8, 1) === C(8, 7), C(8, 2) === C(8, 6), C(8, 3) === C(8, 5)``

so, amount of ways to lose in the second case are greater.

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

Oh, no-no-no, I've forgotten to multiply everything to probability of success.

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

It depends on the probability of winning.

This is a classic example of bernoulli trial.

P(2 out 3) = (3 Choose 2) p^2 * (1-p)
P(5 out 8) = (5 Choose 8) p^5 * (1-p)^3

solving this:

P^3 * (1-P)^2 >= 15/56

Therefore, the second option is a better choice for the values of p that satisfy above condition.

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

you missed the senario where (2 out of 3) and (3 out of 3) can also win the game, but I am not sure if the rule is "exactly 2" to win.

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

First, compute probability of getting success (2 out of attempts):
1. Compute sample space i.e., All possible outcomes of 3 attempts: 8 BBB, BBN, BNB,...etc. Where B->Basket and N->No Basket.
2. Compute How many of the 8 outcomes above have atleast 2 Baskets in them.
Ans: 4 or 3C2+1 (1 for combination with all 3 baskets).
3. Now final step for challenge 1: Probablity of achieving success (2 out of 3 attemts)=4/8 or 0.5.

Now Challenge 2:
1. 8 attempts, possible outcome combinations are: 256.
2. Number of possible combinations of 5 baskets in these 256 outcomes: 8C5+8C6+8C7+8C8=93.

3.Now compute probability of success for challenge 2 i.e., 5 out of 8 attempts: 93/256= ~0.30

Hence, it is better to take Challenge 1 as Prob of success for it (0.5) is greater than the second challenge

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

It depends.

Let the probability to make a shot be p.

The probability to win challenge one is:

``(3 choose 2) p^2 (1-p) + (3 choose 3) p^3``

since you can win by either hitting two shots or all three shots.

For challenge 2 it is

``(8 choose 5) p^5 (1-p)^3 + (8 choose 6) p^6 (1-p)^2 +(8 choose 7) p^7 (1-p) + p^8``

since you can either make 8,7,6 or 5 of the shots to win.

If the probability p is below ~65% challenge one is the one you should choose, if it's above challenge two. So three point shots --> 1 , layups or free throws (if you are a good free throw shooter) --> 2

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

okay ... probability of winning first game 2/3
probability of winning second game is 5/8
i was taught in 8th grade that to compare two fractions you make their denominators same....
(so take LCM) and the probability of winning first game becomes : 16/24
and the second game becomes : 15/24
since 16/24> 15/24 so the person should play the first game.

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

okay ... probability of winning first game 2/3
probability of winning second game is 5/8
i was taught in 8th grade that to compare two fractions you make their denominators same....
(so take LCM) and the probability of winning first game becomes : 16/24
and the second game becomes : 15/24
since 16/24> 15/24 so the person should play the first game.

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

In first game, you have to score 16 out of 24
In second game, you have to score 15 out of 24

Scoring 15 is easier than scoring 16
So why will you choose 1st game.

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

okay ... probability of winning first game 2/3
probability of winning second game is 5/8
i was taught in 8th grade that to compare two fractions you make their denominators same....
(so take LCM) and the probability of winning first game becomes : 16/24
and the second game becomes : 15/24
since 16/24> 15/24 so the person should play the first game.

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

Let,
A = the event that you make 2 out of 3 baskets
B = the event that you make 5 out of 8 baskets
p = the probability of a single success (i.e. you make a basket)
q = the probability of a single failure (i.e. you miss the basket)
Then you should always choose event A (the first option) over event B (the second option).

Note that:
3 choose 2 = 3!/[(3-2)!*2!] = 3
8 choose 5 - 8!/[(8-5)!*5!] = 56
Pr(A) = 3*(p^2)*(q^1)
Pr(B) = 56*(p^5)*(q^3)

And hence we should the first option over the second option when: Pr(A)/Pr(B) > 1
or equivalently when: Pr(B)/Pr(A) < 1
Note that we are indifferent between option 1 and option 2 when Pr(A)/Pr(B) = 1

Finally, note that:

``````Pr(B)/Pr(A) = [56*p^5*q^3] / [3*p^2*q]
= 56/3*p^3^q^2
<= 56/3*(1/2)^3*(1/2)^2
= 56/3*(1/2)^5
= 56/3*(1/32)
= 56/96
< 1``````

And therefore, since Pr(B)/Pr(A) < 1 for any value of p between 0 and 1, we conclude that the first option is always "better" (i.e. more likely) than the second option.

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

Let,
A = the event that you make 2 out of 3 baskets
B = the event that you make 5 out of 8 baskets
p = the probability of a single success (i.e. you make a basket)
q = the probability of a single failure (i.e. you miss the basket)
Then you should always choose event A (the first option) over event B (the second option).

Note that:
3 choose 2 = 3!/[(3-2)!*2!] = 3
8 choose 5 - 8!/[(8-5)!*5!] = 56
Pr(A) = 3*(p^2)*(q^1)
Pr(B) = 56*(p^5)*(q^3)

And hence we should the first option over the second option when: Pr(A)/Pr(B) > 1
or equivalently when: Pr(B)/Pr(A) < 1
Note that we are indifferent between option 1 and option 2 when Pr(A)/Pr(B) = 1

Finally, note that:

``````Pr(B)/Pr(A) = [56*p^5*q^3] / [3*p^2*q]
= 56/3*p^3^q^2
<= 56/3*(1/2)^3*(1/2)^2
= 56/3*(1/2)^5
= 56/3*(1/32)
= 56/96
< 1``````

And therefore, since Pr(B)/Pr(A) < 1 for any value of p between 0 and 1, we conclude that the first option is always "better" (i.e. more likely) than the second option.

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

The first one is better. We have to consider the probability of basket P in each shoot. However, for all P within (0,1), we have the first choice is better.

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

i don't understand some of the answers here:

Assuming equal probability of hitting all baskets irrespective of how many are thrown:

2/3= 16/ 25 that need to be made to win

5/8= 15/ 25 that need to be made to win

so 5/8 is better as you need less successes to win

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.