Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

int c2=0,c3=0,c5=0;
   a[0]=1;
   for (int i=0;;i++)
   {
        int min=getMin( 2*a[c2], 3*a[c3], 5*a[c5]);
        if (min==2*a[c2]) a[i]=2*a[c2];
        else if (min==3*a[c3]) a[i]=3*a[c3];
        else a[i]=5*a[c5];
        
        if (min==2*a[c2]) c2++;
        if (min==3*a[c3]) c3++;
        if (min==5*a[c5]) c5++;
    }

- jobseeker April 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

this will print 6 twice, 10 twice, three 12, ...and so on.

- Anonymous April 19, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

hey @anon: his code is correct. did you care testing it before writing your worthless comments ?

- Anonymous April 19, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

here is what I got:

2 3 4 5 6 8 9 10 12 15 16 18 20 24 25 27 30 32 36 40 45 48 50 54 60 64 72 75 80 81 90 96 100 108 120 125 128 135 144 150 160 162 180 192 200 216 225 240 243 250 256 270 288 300 320 324 360 375 384 400 405 432 450 480 486 500 512 540 576 600 625 640 648 675 720 729 750 768 800 810 864 900 960 972 1000 1024 1080 1125 1152 1200 1215 1250 1280 1296 1350 1440 1458 1500 1536

- Anonymous April 19, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Not getting this. If c2,c3, and c5 are incremented, how do we get numbers like 125 , ie pow(2,0) * pow(3,0) * pow(5,3)

From the above code, i was getting a different sequence. Not sure how,

2 4 6 8 10 12 16 18 20 24 30

- GingerBreadMan April 19, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@ GingerBreadMan: You are right. I did a small mistake. i should start from 1 not 0. so second row is as follows:
for (int i=1;;i++)

- Anonymous April 19, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@ GingerBreadMan: You are right. I did a small mistake. i should start from 1 not 0. so second row is as follows:
for (int i=1;;i++)

- jobseeker April 19, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Like

- jiangok2006 July 17, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. take 3 min priority Queues

Q2 // stores 2 prime no combination no.s like 2, 2*2, 2*3 , 2*5
Q3 // stores 3 prime no combination no.s like 3, 3*3, 3*5 ( no need to store 3*2 since it is already stored in Q2 queue )

Q5 // stores 5 Prime nos like 5,5*5 , 5*5*5

2. min = getMin( Q2, Q3, Q5 )

if( min == min(Q2 ) )
{
delete min from Q2;
add (min*2, Q2 ) ;
add (min*3, Q2 );
add ( min *5, Q2);
}

else if( min == min(Q3 ) )
{
delete min from Q3;
add (min*3, Q3 ) ;
add ( min *5, Q3);
}
else
{
delete min from Q5;
add ( min *5, Q5);
}

3. print min . do step 2 and 3 for 100 times to print 100 min no.

- siva.sai.2020 April 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

there is a cheeky way of solving this. Keep Count of all Prime numbers. the 100th number will be 1xx - xx where xx is the number of primes .... But figuring out whether is a number is prime or not is NP complete.. Just saying!!

- dilip.rangarajan May 05, 2012 | 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