www.amazon.jobs /  HQ: Seattle, WA

604 Interviews in Hyderabad (of 18,244)

3.2 Average

www.deloitte.com /  HQ: New York, NY

500 Interviews in Hyderabad (of 10,118)

3.1 Average

www.infosys.com /  HQ: Bengaluru, IN

461 Interviews in Hyderabad (of 6,999)

2.8 Average

Sort: RelevancePopular Date

15 Apr 2013

29 Feb 2012

1 Apr 2010

5 Jul 2012

### Software Development Engineer at Amazon was asked...

24 Sep 2012
 Given an array of numbers, nums, return an array of numbers products, where products[i] is the product of all nums[j], j != i. Input : [1, 2, 3, 4, 5] Output: [(2*3*4*5), (1*3*4*5), (1*2*4*5), (1*2*3*5), (1*2*3*4)] = [120, 60, 40, 30, 24] You must do this in O(N) without using division.13 AnswersWell my answer was to divide the array in 2 different parts perform some logic and in end multiply both the arraysOne solution would probably be to go through entire array once, keep a track of total product, and then in another loop populate result array by setting each index as totalProduct / (value at index in argument array)oh.. but without division. Didn't see that part with my tiny browserShow more responsesIf you were not supposed to divide the array into two, for processing.... import java.util.*; class aNum2{ public static void main(String[] args){ int[] a= new int[5]; int[] b= new int[5]; a[0]=1; a[1]=2; a[2]=3; a[3]=4; a[4]=5; int j; for(j=0;j<5;j++){ int i; int p=1; for(i=0; i<5; i++){ p=a[i]*p; } b[j]=p/j; } System.out.println(Arrays.toString(b)); } }if you werent supposed to use the division operator : import java.util.*; class aNum{ public static void main(String[] args){ int[] a= new int[5]; int[] b= new int[5]; a[0]=1; a[1]=2; a[2]=3; a[3]=4; a[4]=5; int j; for(j=0;j<5;j++){ int i; int p=1; for(i=0; iPlease ignore the very first response .. there is a correction on line 20 If you were not supposed to divide the array into two, for processing.... import java.util.*; class aNum2{ public static void main(String[] args){ int[] a= new int[5]; int[] b= new int[5]; a[0]=1; a[1]=2; a[2]=3; a[3]=4; a[4]=5; int j; for(j=0;j<5;j++){ int i; int p=1; for(i=0; i<5; i++){ p=a[i]*p; } b[j]=p/a[j]; } System.out.println(Arrays.toString(b)); } }trick is to construct the arrays (in the case for 4 elements) for example { 1, a[0], a[0]*a[1], a[0]*a[1]*a[2], } // productsBelow { a[1]*a[2]*a[3], a[2]*a[3], a[3], 1, } // productsAbove then multiply productsBelow and productsAbove http://stackoverflow.com/questions/2680548/interview-q-given-an-array-of-numbers-return-array-of-products-of-all-other-nu#include using namespace std; int main(){ int a[4] = {1,2,3,4}; int b[4] = {1,1,1,1}; for(int i = 1 ; i =0; i--){ prod *= a[i+1]; b[i] *= prod; } for(int i = 0; i < 4; i++){ cout << b[i] << " " << endl; } }public class Example2 { static int[] Numarray={1,2,3,4,5}; public static void main(String[] args) { ArrayList arr1=new ArrayList(); int first=0; int count=1; for(int j=0;j<=Numarray.length-1;j++) { for(int i=0;iThere should be no divsion of array not even numbers so the solution goes like this //SIMPLIFIED APPROACH class amazon2 { public static void main(String rags[]) { int []a={1,2,3,4,5};//any digits as per approach int []b=new int[10]; int []c=new int[10];//dummy integer array for(int i=0;ipublic void printProduct(int[] a) { int[] b= new int[a.length]; for(int j=0;jpublic void printProduct(int[] a) { int[] b= new int[a.length]; for(int j=0;jprodSum = function (arr, memo, index) { if(index >= arr.length){ return; } for(var i=0; i

### Senior Software Engineer at Amazon was asked...

13 Oct 2012
 You are given a fixed number of 5 rupee, 10 rupee, 20 rupee and 50 rupee stamps. Now given an amount for sending a parcel, you should design an algorithm to come out with the minimum number of stamps that should be used for attaining that amount. For example, if the parcel costed 30 rupees, it could be attained using one 20 rupee stamp and one 10 rupee stamp OR using three 10 rupee stamps OR using one 20 rupee stamp and two 5 rupee stamps OR using one 10 rupee stamp and four 5 rupee stamps OR using two 10 rupee stamps and two 5 rupee stamps. However, the minimum number of stamps is the case of one 20 rupee stamp and one 10 rupee stamp where only two stamps are used. The case where no solution is possible should also be handled, for example, a parcel amount of exactly 33 rupees cannot be attained.8 AnswersThe solution is attained using dynamic programming. The basic idea is that the minimum number of stamps used for attaining an amount x, is 1+minimum of (minimum number of stamps for attaining x-5, minimum number of stamps for attaining x-10, minimum number of stamps for attaining x-20,minimum number of stamps for attaining x-50). You can try to solve this first by assuming that an unlimited number of 5 rupee, 10 rupee, 20 rupee and 50 rupee stamps are available. And then you can take into account that only a fixed number of these stamps are available.And what is the time involved to get this done? I really liked the question.Simple to read but involves good amount of logic. I ve written down the algorithm but i believe i took more time than i initially thought i would take.I understand what the interviewer is trying to test and I know how to solve it, but what about more realistic scenario where parcel postage cost would be beyond given values like 3 units of currency or 37 units of currency.Show more responsesIn this specific case, dynamic programming is overkill. There's a better optimal substructure here: The stamp with greatest value less than parcel cost minus stamp values already committed minimize the total of stamps.1. find the stamp <= cost from highest stamp cost 2. num of found_stamp = found_stamp/cost, rem_stamp = found_stamp % cost 3. Do 1, then 2 until rem_stamp ==0 (done) or rem_stamp < least stamp available (not possible case)In the previous ans, after step 3 if rem_stamp !=0, go back to step 1, find next_stamp < cost (but smaller than value of found_stamp in previous iteration)i=0; boolean solPossible = false; do { if(cost % notes[i] == 0) solPossible = true; else i++; } while(!solPossible && (ivoid sendParsal(int cost) { int[] avlstm={50,20,10,5}; int i=0; while(cost>=5) { while(cost>=avlstm[i]) { System.out.println(avlstm[i]); cost=cost-avlstm[i]; } i++; } if(cost!=0) { System.out.println("Solution not possible."); } }

### Software Development Engineer at Microsoft was asked...

12 Jul 2013
 out of 25 horses select the fastest three in minimum number of races where in each race there would be exactly five horses.10 Answers6 races i thinkit could be 6 races... first five races taking 5 horses each,and then the 6th ace taking the 1st horse of each of the previous race,den select the fastest three among them.would be 5 races if a stop watch is given..... however solutions given before are wrong since the horse coming 2nd in the first race might be faster than the horses that come first in the subsequent race :) hence we have to assume that a timer is providedShow more responsesumesh no timer has been provided and it would be 7 races :)11 races First 5 races taking 5 horses in each race. Next 5 races taking in each race horses which have come first, horses which have come second, third, fourth and fifth....... Final 11th race out of 5 which have won in second set of races to find fastest 36 Race would be wrong answer. What if in one group all the 5 horses are fastest of all others. Then from first round of 5 races we might lose those 2nd and 3rd ones. My answer is also 11 Races.Round one - 5 Races -------------------- Including all 25 horses. 5 each race. Left with -> 15 horses [Take 1st,2nd & 3rd from each race. Which would be total of 5*3=15 horses.] Round two - 3 Races [ Grouping any 5 of 15 horses left] ------------------- Left with -> 9 horses [Take 1st,2nd & 3rd from each race. which would be total of 3*3=9 horses.] Round three - 1 Race. ---------------- Take any 5 horses of 9 horses left Left with -> 7 horses 3 (1st 2nd and 3rd) + 4 (remaining ones) = 7 horses Round four - 1 Race. ---------------- Take any 5 out of 7 Left with -> 5 Round Five - 1 Race ---------- Race of 5 horses left7 races: Split the 25 into 5 groups and make them race, this would be 5 races. Take the fastest horse of each group and make them race (6th race). Let's label the initial group of the top 3 horses of the 6th as a, b, c. The possible candidate for the 3 fastest are: a[1], a[2], a[3], b[1], b[2], c[1] We just need one last race to determine the top, the race would be between a[2], a[3], b[1], b[2], c[1]. The final result is a[1] then the top 2 of the 7th race.Easy: Correct answer is 11 but much easier method: 1. One race among 5 horses to find the fastest 3. 20 horses left not raced yet. 2. Now keep the 3 fastest horses you found and add two other horses out of 20 horses left to the race, again select the fastest 3. 3. Keep doing this for all 20 horses by selecting 2 of the horses left to race against the fastest 3 always. 1 race (to find the fastest 3) + 10 races (20/2 races to test all other 20 horses) = 11 racesConstant Time - 7 Races 5 Races among 5 each. 6th Race for all third place holders 7th Race for Winner of sixth race +two people who defeated him in 1st race + two people who defeated the second place winner in 6th race. Best Case - 6 Races (3 place winner of 1st race against other 20 and he wins all the time) Worst Case - 11 Races( Make the fastest 3 of each race run against the other 2 each time)

31 Jul 2013
 what is angle between hour hand and minute hand in clock at 4:20 ? what is biggest conflict management you have handled in your work place11 Answers4:20 - ANGLE WOULD BE 120 CIRCLE IS 360 DEGREES , EVERY 5 MINUTES = 30 DEGREESIF min's hand rotates for 360 deg, hr's hand rotates for 30 deg - so for 60 min - hr's hand rotates for 30 deg. For 1 min it rotates for 0.5 degree. Hence, for 20 min it rotates for 10 degrees. The angle between hr's hand and min's hand should be 10 deg.have you ppl looked at an analog clock recently it is 0 or 360 degreesShow more responsesThe angle between hour and minute hand in 4:20 is 10 degrees. For a minute, the hour hand rotates by 30/60 = 1/2 degrees. hence, for 20 minutes it rotates by an angle of 20*1/2 = 10 degrees.The formula is 180 - | 180 - | m * 6 - (h * 30 + m * 0.5) |Heres the complete formula.. for better understanding.. ABS is absolute value 180 - ABS (180 - ABS ( m * 6 - (h * 30 + m * 0.5) ) )An analogue clock is degrees. 360/12=30 degrees per hour 360/60=6 degrees per minute So for 4 hours - 30*4=120 degrees For 20 mins - 20*6=120 degrees therefore, Answer is zero20 minutes is 1/3 (20/60) of the way around the dial, 4 o'clock is also 1/3 of the way around a clock (4/12), so they are perfectly aligned and the angle between them must be zero.There are two approaches to this question: - If you assume the hour hand stays put and only moves every hour o'clock (which is a simplification, but a reasonable one), then the angle is 0º. - If you assume the hour hand rotates at a constant angular speed, then the answer is 10º. Since there's 360º / 12 = 30º between hours: + The minute hand points at 4. That's 30º x 4 = 120º. + The hour points slightly past 4. Since a third of the hour has passed (20' = 60' / 3), then the minute hour has moved a third of the way between hours. Hence the hand is at 120º + 30º / 3 = 130º. The difference between the two hands is 130º - 120º = 10º So I guess you get some poits for saying 0º, more points for saying 10º. My question is, did you get to use pen and paper, or you had to answer on the spot?in every 60 minutes hour hand moves 30 degrees. so at 14:20 ( it means that 20 minutes have past since last turn) hour hand moves 20*30/60 = 10 degrees so the answer is 10 degrees...360/(12*3) = 10