Amazon Interview Question for Software Engineer / Developers






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

This is a very common question.

k = a + b;

first approach:
Sort the array and take two pointers, one at the begining and one at end.
if((*p1 + *p2) < k){
++p1;
}
else if ((*p1+*p2) > k){
++p2;
}else{
print *p1 and *p2;
}

second approach.
Use Hash Table to store array elements and check if u can find a and b such that a+b = 20

- algooz June 16, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1 little optimization is possible
We need 2 numbers 1 <= 20/2 and 1 >= 20/2.
So we take the list and sort it.
Do a binary search on 20/2 = 10 (or more generically lower bound n/2)
and lets say you have ended up in location k (if k =0 or n-1) u can stright
away say you dont have any elements that sum up to 20

and have 2 pointers 1 running from 0->k and from k->n-1. summing up and checking
if equals 20

- prasanna.raj August 21, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Generate Hash Table with H(n)
Repeat the process for H(S-n),
If Collisioncount>=2, return true
else return false

- YetAnotherCoder October 01, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 0 vote

If there are no duplicates in the array.....create another array with elements as [20 - arr[i]]...merge these 2 arrays....if now the array has duplicates, it means there is a and b totalling to 20...

- Nikhil Limaye June 24, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

your solution fails for following input
7 8 9 10 11

Because the other array will be
13 12 11 10 9

You have 10 as duplicate, but it is does not form 20.

- AKS August 07, 2008 | 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