Amazon Interview Question for Software Engineer / Developers






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

use hash table,
in linear time.

- Anonymous August 27, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 0 vote

Let N = given number
1. Sort the array into ascending order. O(n logn)
2. For every number(n) in the array search for (N-n) using Binary
search. [n* O(logn) = O(n logn)]
3. If found : return success
else failure
Total runtime = O(n logn)

- Chetan February 19, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Nice solution!
Works for negative numbers, positive and their mix in the array..

- LA August 24, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Sort array A of n numbers
Keep one pointer p at n/2 number
Keep second pointer q at n/2+1 number
Take sum of the two numbers S = A[p]+A[q]
while(p>=0 and q<n)
{
if(A[p]==A[q])
return true
while(S>N&&p>0)//N is required sum
{
p--;
S=A[p]+A[q];
}
while(S<N&&q<n-1)
{
q++;
S=A[p]+A[q];
}
}
return false;
End

- Anonymous October 17, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How can we use the hash table. Can anyone plese explain??

- Sadineni.Venkat October 20, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

a). Sort the array in O(NlogN) time.
b). Start i=0 and j=last element. and lets call the sum required to be S.
c). Calculate a[i] + a[j] and
1). If a[i] + a[j] > S, then decrement j
2). If a[i] + a[j] < S, then increment i
3). If a[i] == a[j], you have the answer
d). repeat until i < j.

- loonyCoder October 25, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

using hash table:
(assume the given number is N)

for each number in the array:
- check if there is a key (N-number) in the hash table
- insert it to hash table as the number is the key

linear time

- Benny October 30, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1). Sort the array. (NlogN)
2). For each number x, find s-x using binery search. (N*logN).

Not any better. But an alternative.

- Hari. September 21, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Sorry. already mentioned above..

- Hari September 21, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

the smart answer is to use binary search after sorting the list.

- Anonymous October 08, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

sort the array(O(nlogn))
keep two index variables one at each end of the sorted array
if the sum of values at the two indices is less than given value increment left variable ;else if it is greater than given value decrement the right variable; else,
we have found the variables.
continue this until the two index variables cross in which case no two integers sum up to given value.

- eshwar August 24, 2008 | 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