Amazon Interview Question for Software Engineer / Developers






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

- We can try by throwing the dice two times.

- Now we have 36 events.. How do we divide the events so that the probability of even number is more than that of odd numbers ?

It can be done like this ..

a. When two consequtive even number comes - consider it even.
b. When we get two odd - consider it odd.
c. When we get two even - taken the second even.
d. When we get one even and one odd - take this even ( this is main).

With the above strategy - there are 27 events with even numbers and 9 events with odd numbers..

So this turns out - 3/4 (Probability for even) and
1/4 (Probability for odd)..

- Rinks September 19, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I don't understand your answer. So I write one, hope it works.

rv = rand(0,1); //uniform distribution: (0,1)
result = (int)(3*rand(0,1))+1; //1,2,3 - uniformly
if(rv<0.72) // the probability
return 2*result;
else
return result;

- elfy January 04, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think that both results here are a little off. Even here is 2,4,6 while odd is 1,3,5. Here's my answer:

public static int rollDice ()
{

// Are we going to do even or odd?

int eo; // 0 means we're going to be odd, 1 means even

if ( Math.random() > 0.72 )
eo = 0;
else
eo = 1;

// Generate an odd number (1, 3, 5)

int result = ( (int)( Math.random() * 3 ) * 2 + 1 );

// If eo is 1, adding it to the result makes it even (2, 4, 6); otherwise, it remains odd

result = result + eo;


return result;
}

- Breadinator January 11, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

make it simplier:
72% probability to get a even number (2, 4, 6), then each even number has a probability of 72%/3 = 24%.
Similarily, each odd number has a probability of 28%/3 = 9.3333%

- Anonymous March 14, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The simulation program would typically involves generating random number between and 0 and 1 and check in which range it falls in. For equal probability it should be in range of ( 1/6, 2/6, 3/6 ... ) to bias it we can shift the range. i.e for 72 percent we can have ( 0-28/300, 28/300 - 100/300, 100/300 - 128/300 ,...). In this way we can have biased no for even no generator.

- neo March 31, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Could you please explain in detail.I didnt quite get it....

- swathi April 01, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Could you please explain in detail.I didnt quite get it....

- swathi April 01, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

when u generate a random number n between 0 and 1, for equal probability, u assign the following way
0 - 1/6 = 1; 1/6 - 2/6 = 2; 2/6 - 3/6 = 3; 3/6 - 4/6 = 4; 4/6 - 5/6 = 5; 5/6 - 6/6 = 6

now for the even numbers to have 72% prob, we have to divide each 1/3rd into 1/3 * 28/100 and 1/3 * 72/100 i.e 28/300 and 72/300
now the ranges will be
0 - 28/300 = 1; 28/300 - 2/6 = 2; 2/6 - 128/300 = 3; 128/300 - 4/6 = 4; 4/6 - 228/300 = 5; 228/300 - 6/6 = 6

this way u get the biased probability of 72% for even numbers

- rkt April 01, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

x = rand() * 100;
t = 75; //your bias
return ((x%3)+1)*2 - (x<t)? 0: 1

- BabelFish April 01, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

All those fuckhead PhD from GOOGLE, AMAZON, MICROSOFT should design a method how to fuck their mothers. Only then they will stop arguing and opposing you whatever you say. These ass holes should be banned from interviewing. Mother fuckers should interview their own mothers and fathers. They should burn their PhDs as they do no research and waste public money. Fucks should rot in hell.

- frei April 02, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

so, your interview didn't go well?

- NewStart April 02, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you give some explanation of this statement?... ((x%3)+1)*2 - (x<t)? 0: 1

- andy April 06, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can somebody plz explain me the question? I did not get what is he asking for...
"...when a dice is thrown in 72%..." what do u mean by this sentence?

- andy April 06, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

x=rand()*100;
if(x<=72)
x=(rand()*3)*2;
if(x>72)
x=(rand()*3)*2-1;

I think this works fine

- Anonymous April 09, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

sorry, mistake
x=rand()*100;
if(x<=72)
y=(rand()*3)*2;
if(x>72)
y=(rand()*3)*2-1;

- Anonymous April 09, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Rinks solution (Ist one) is correct

- M August 16, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Suppose we want to achieve a probability of p%, where p is an integer between 50 and 100.

Here, we can simply try to generate a random number between 0 and 99, and compare it against p.
There is a standard problem Amazon gives that asks that you generate a uniformly random number between 0 and 6 given a generator that produces numbers between 0 and 4. We can use a similar approach here.
Generate a 3-digit base-6 random number by rolling a die three times. That number will be between 0 and 215 inclusive (in base 10). If the number is larger than 199, throw it away and find another one. Otherwise take its modulo 100, and you have a random number between 0 and 99 to compare to p.

This is with a minimum of 3 die rolls. We need at least that many unless p is some very nice integer (say 75; we can do a probability of 3/4 in two throws).

- mathytime September 22, 2014 | Flag Reply


Add a Comment
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.

Learn More

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.

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