Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

The probable catch in the logic is when there is overflow upon addition.

The best logic for this flow of finding an average of 'n' numbers is:

double avg=0;
for(i:1 to n)
avg += (double)Arr[i] / (double)n;

ie., (a+b+c)/n = a/n + b/n + c/n

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

Nice...

- Red Lv April 05, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

cool...

- sreeram September 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

good catch dude..

- Amit September 27, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Let A1.....An be the input array.

for (i=1 to n) {
total = total + A[i];
}
avg = total/n;

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

what if the sum exceeds the integer limit?
first divide and then add. That is the correct way to go!

- Prince Mishra April 07, 2012 | Flag


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