Amazon Interview Question for Software Engineer / Developers


Country: -




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

Assuming array has n elements, sum should be equal to S.
Create a boolean array with S+1 elements, with first element as true rest as false.
for i in (n elem array):
for j in booleanArr:
if booleanArr[j] == true:
booleanArr[j+i] = true

return booleanArr[S]

- sausax September 15, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

if I consider my elements are 5,3,12,1,6 and if i check to see if 25 can be generated .. according to this algorithm it will return true but it shouldn as you cannot repeat the same element more than 2 times to generate the sum .. in this case 25 can only be formed by 12+3+5+5 ... Please correct me if I am wrong ..

- fchristopher239 November 25, 2011 | Flag
Comment hidden because of low score. Click to expand.
1
of 3 vote

Yes there is solutiuon based on dynamic programming and also another technique which runs in O(n*2^(n/2)) check wikipedia for the solutions

- Anonymous September 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Everyone know it's dynamic programming. So what's the solution? At least give a url to a solution?

- Jon September 13, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is a perfect answer: Dynamic programming for small values and O(n * sqrt(2^n)). Wiki page on subset sum has it. How much spoon feeding does one need?

Idiots voting incorrectly...

- Anonymous September 13, 2011 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

This is subset sum problem, which is known to be NP complete. So, there is no known solution with complexity better than O(2^n).

- Anonymous September 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The above comment is utterly wrong.

1) It is NP-Hard and not NP-Complete. NP-Complete is reserved for _decision_ problems.

2) Being NP-Hard does mean there can't be better than Theta(2^n) algorithms.

3) There are known O(n sqrt(2^n)) algorithms. See the wiki page and look for Sahni's divide and conquer algorithm.

- Anonymous September 13, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I guess what you mean is NP but not P
because when you say NP-Hard but not NPC it mean problem is not solvable for all possible inputs.

Plz correct me if i am wrong

- hardbug September 13, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@hardbug: You are wrong. NP-Hard means at least as hard as any problem in NP. NP complete means, NP-Hard _and_ in NP. So NP-Complete is a subset of NP-Hard.

NP-Hard does not mean unsolvable/undecideable. There might be NP-Hard problems for which this is true (like Halting problem), but that it not necessarily the case for all.

Deciding if a subset exists which sums to a given number is NP-Complete (decision problem), but actually finding the subset is NP-Hard (it is not a decision problem and so is not in NP).

- Anonymous September 13, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

The problem is NP-complete.

- Leo September 19, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

LEO, read again.

- Anonymous September 19, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use meet in meet in middle algorithm

- Learner September 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use meet in meet in middle algorithm

- Learner September 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This is subset sum problem, which is known to be NP complete. So, there is no known solution with complexity better than O(2^n).

- Anonymous September 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

at least plaese give the link i tried bit could nt found it

- kamal September 14, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

at least give ur logic please.

- Anonymous September 14, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

sumBool(i, s) = sumBool(i-1, s) || (arr[i] == s) || sumBool(i-1, s-arr[i])

- Anonymous September 19, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

create a hashmap for each element in the array which takes O(n) and takes the first element subtract it from the number that need to be searched in the array, if it exists in the hashmap then return both the integers, else similarly do for the other elements in the array .. so the total complexity O(2*n) and space complexity is O(N)

- Gopinath V December 11, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.


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