Amazon Interview Question for Software Engineer / Developers






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

My answer I gave was to put all the numbers in a hash table where the key where the numbers and the values where the number of times the number was seen. Then just go through all the numbers and see which ones are not divisible by 2. This was the best answer I could come up with on the spot, and I wasn't able to answer the last part of how it could be done without another data structure.

- JayNeedsAJob January 15, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

XOR all of 'em

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

Awesome answer man

- newbie January 15, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Thats a great answer!

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

Really fantastic answer

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

You are a genius! That was so simple why didn't I think of that when they asked me?! Thanks for the simple solution, I'll keep bit-wise operations in mind next time :p

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

You are a genius! That was so simple why didn't I think of that when they asked me?! Thanks for the simple solution, I'll keep bit-wise operations in mind next time :p

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

sexy answer dude..

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

Genius? People, I hope you realize that this is a classic answer that most of smart people know the answer to. Thnx.

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

result = 0;
for each element
{
result ^= element[i];
}
return result;

- Roshan Mangal January 15, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

good job

- elx January 16, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

sum all the numbers. subtract one element at a time, if result is even the number just subtracted is answer. the xor solution is best imo.

- dsk January 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Cool.

- Mugdha January 18, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think this should not work..

Consider.. 2,2,3,3,4,4,5

Sum = 23

So according to your algo answer should be 3 but this is not the case.

Please correct me if I am wrong...

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

Are u sure for XOR answer ??


public class Xor {

public static void main(String[] args) {
int arr[] = { 1,1,1,2,2,3,4,4,4,7,7,5};
int result = 0;
for (int i = 0; i < arr.length; i++) {
result = result ^ arr[i];
//System.out.println( (i+1) + ": " + result);
}

System.out.println("Final Result : " + result);

}
}

The result that was given is 3 instead of 2 .

- Hi January 20, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

XOR is best solution. You have taken wrong input. only one number occurs odd time and rest all numbers occurs in even times..

- Niteen Borge January 28, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

@Hi : Always read the question carefully.
XORing is the best answer for such even-odd occurrence questions.

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

Just FYI to any potential Amazon interviewees -- this question or a variation of it is VERY common, and I've seen it every time I was interviewed. Knowing the XOR answer will put you ahead of a lot of people.

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

Hi ,

I just thought of another way of doing it.

product all the numbers.
divide the product by each of the numbers. Find the square root of the division. If its whole. then the integer is odd one. as even number of integer multiplication should have whole square root.


but again no zeroes here. but seriously,, how the hell did u come up XOR man??!!

- cool January 28, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Q: An integer array where there are repeating numbers and all but one repeat an odd number of times ex [ 2,2,2,4,4,7,7,7,3,5] 4 repeats even number of times, [2,1,7,3,3] 3 repeats even number of times . Find it

A: Do an XOR of the corresponding bits of integers in the array, and do a NOT on the result

- KK January 28, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

this won't work.. try (2,3,5,5) your solution doesn't give 5.

- sundar January 31, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

a good test case for this solution is, {0,1,1,2,2} ;-)

- anony February 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Please read the question carefully it is not that straight forwards "All but one is repeated even number of times" and we have to find any one which is repeated odd number of times. So, here the XOR wont work.

- Anonymous February 09, 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