Amazon Interview Question for Software Engineer / Developers






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

What is so special about it?

- hary February 20, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

max = INTEGER.MIN
for elem in myarray:
if elem > max:
max = elem
print max

big-O is O(n)

- binary bill February 20, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

whoops, i mean

max = INTEGER.MIN
for elem in myarray:
  if elem > max:
    max = elem
print max

- binary bill February 20, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

It is better to use the divide and conquer method - MaxMin algorithm (except we only want the max value) - reason: it reduces the number of comparisions. See the algo below..

Max(arr,start,end,max) {
     if(start == end) {
        max = arr[start];
        return;
     }
     if(end - start == 1) {
        max = arr[end] > arr[start] ? arr[end] : arr[start]
        return;
     }
     else {
        mid = (start + end) / 2;
        Max(arr,start,mid,max1);
        Max(arr,mid+1,end,max2);

        max = max1 > max2 ? max1 : max2;
        return max;
     }
  }

- aquila.25 February 21, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

What is the running time of this Algorithm?
Looks like you will end up comparing more than n times...
Let me know if I m wrong.

- Pandu February 21, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think that the solution is actually O(n). It's like a mergesort, except without the merge. Problem divides into two parts, and each part halves the problem.

- Anonymous February 22, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yes it is still O(n) but if you research a little the Divide and Conquer approach has (3n/2)-2 is the best, avg and worst case number of comparisions. With the straight approach the worst case (when the max is at the end of the list) the # of comparisions made is 2(n-1), hence the Divide and Conquer approach is preferred.

- aquila.25 February 23, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

where it is told that list is sorted??

- aqui February 24, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

this kind of context-less question is exactly why this website is becoming less helpful

- Anonymous February 21, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is the question asked by AMAZON person in the interview and i believe this website is used to help people prepare for their interviews. There is nothing wrong in posting questions that have been asked even though it is simple.These might help a lot of people.

- Anonymus February 22, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is the question asked by AMAZON person in the interview and i believe this website is used to help people prepare for their interviews. There is nothing wrong in posting questions that have been asked even though it is simple.These might help a lot of people.

- Anonymus February 22, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

What does this means ?

- Anonymous February 21, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int main() {
printf("test\n");
return 0;
}

- test February 23, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int main() {
printf("test\n");
return 0;

}

- test February 23, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Normal method takes O(n). Building a max-heap takes just log(n).

- Helper April 07, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Building the max heap - O(nlogn)
Finding the max in the heap - O(1)

- anon June 02, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Overkill

- Anonymous July 05, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think a optimal soultion would be a genetic dynamic pgoramming implementation of fermat's theorem using fourier transforms

- Anonymous May 10, 2011 | Flag Reply


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