Amazon Interview Report
- 0of 0 votes
Answers - SameerShah21 October 21, 2011 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 0of 0 votes
AnswersIn a 3d space find points 10 points that are closest to the origin. Which data structure would you implement. What would be the time complexity of such a program.
- SameerShah21 October 21, 2011 in United States
I said that I would maintain 10 arrays that stores (x,y,z) coordinates and 10 int var to store the distance value.
int coordinates1[],value1,coordinates2[],value2,coordinates3[],value3....
We would start calculating Euclidean distance of the given point in hand and store it in those 10 arrays. As soon as we got 11th point we would replace it with the array corresponding to the highest value in the array.
As soon as we got the 12th point we would replace it with the 2nd highest corresponding value array ...after traversing through every point we would have the nearest 10 coordinates. I read this somewhere on career cup. I just modified the idea a little to accommodate 3d realm.
He asked what is space complexity. I said 10 arrays and 10 int values. A constant number will have a constant value n, O(n). He said fine, what if there are k points to be found. I said still it would be O(n). He said I was wrong it would be O(n square) since k points are inputted. I did not understand that part.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 0of 0 votes
AnswersWrite a program that performs division and outputs quotient. You cannot use division operator.
- SameerShah21 October 21, 2011 in United States
I thought I could do it with mod but I was wrong. He, told that the solution will not work. After keeping the phone down I realized that subtracting the divisor from the dividend and continue this in a loop till dividend >= divisor would be the right way to go (along with other validations like check for 0.)| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer