Amazon Interview Question for Software Engineer Interns


Country: United States
Interview Type: Phone Interview




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

Assuming the arrays are sorted (or sorting them is allowed as a preprocessing step), we can solve this by using binary search. I haven't tried the algorithm, but I am guessing this approach works:

1. Sort the arrays. Let's call them array A, B and C respectively.
2. Iterate the array that has the least number of elements. Let's assume array A has the least number of elements.
3. For every element A[i], find an element B[j]using binary search such that A[i] + B[j] is close to zero. Call this sumX.
4. Using sumX, find an element C[k] using binary search such that sumX + C[k] is zero. Call this sum finalX.
5. If finalX is found, print {a[i], b[j], c[k]} and return true (since the question is to find if such a set exists).
6. If finalX is not found, repeat steps 3-6 until end of array A is reached.
7. Return false if finalX is not found and end of array is reached.

Have I missed something? Let me know if this solution passes all test cases.

- maximus September 08, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

This will not work since in steps 4-6, we are looking for only one element in arrays B and C that add up to zero with the chosen element in A. We have to look for a set of numbers in B and C in order to make sure if such a set exists.

- maximus September 08, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

For those who r not getting the question.i will explain.nyway nice question karan
ok now for those who r not getting the question,this question is about picking one element from each array of total n array and add up these number to make it zero.hope it is clear.
will post solution soon.
I have a solution but that is not proper (as we make n^n different set ,among these set we have to find one set whose sum is zero) but this way is not proper.

- go4gold March 22, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Thanks for making it clear to others.
I came up with the solution that is n^n. but i want something more effiecient

- Karan March 27, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

A solution better than n^n ??? whoa .... AMZN guys are really something,
we can have n^n-1 solution as far as I know ... Let me know if you guys got a better solution ... I will tag this post.

- pras April 09, 2014 | 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