Amazon.com Interview Question
1,578 Interview Reviews |
Back to all Amazon.com Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Software Engineer at Amazon.com:
Phone interview 1: 1. Describe what a hash map/table is. Later evolved into how to deal with collisions. 2. Write the code to take an int array and return a new int array whose value at i is the product of all values in the input array except the value at i.
Helpful Question?
Yes |
No
Inappropriate?
Answers & Comments (3)
int right = 1;
for (i = 0; i < n; i++)
OUTPUT[i] = 1;
for (i = 0; i < n; i++) {
OUTPUT[i] *= left;
OUTPUT[n - 1 - i] *= right;
left *= arr[i];
right *= arr[n - 1 - i];
}
Helpful Answer?
Yes |
No
Inappropriate?
int arr[100] = [...];
val = 1;
for(i=0; i < size(arr) ; i++)
val *= arr[i];
for(i=0;i < size(arr);i++)
arr[i] = val / arr[i];
Helpful Answer?
Yes |
No
Inappropriate?
To comment on this
question,
Sign In with Facebook or
Sign Up



1 of 1 people found this helpful
by Interview Candidate:
2. My original implementation was the brute force n^2 implementation of multiplying everything but the ith element. This was later refined to first get the product, then divide by the ith position when construction the output array. Special cases had to handle 0's.