Amazon Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: In-Person
hey @anon: his code is correct. did you care testing it before writing your worthless comments ?
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
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: 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++)
@ 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++)
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.
- jobseeker April 19, 2012