Amazon Interview Question for SDE-2s


Country: India
Interview Type: Phone Interview




Comment hidden because of low score. Click to expand.
2
of 4 vote

Can't you just return 0 regardless of the input?

- chriscow January 26, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Ha, yeah...the problem as stated here might allow that, but that seems like an awfully weird interview question.

I was working off the assumption that you needed to take a number and actually mutate it to zero without doing a direct assignment...kind of like how in x86, when you want to zero out a register, you do "xor (reg), (reg)".

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

Then I would do this

return input & 0;

haha

- chriscow January 26, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

[Correct]
Input : 101011
Output : 000000

[Wrong]
Input : 101011
Output : 0

Then how you fix this.

- raghu February 11, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Is anything wrong in either of following two?
1. number & 0;
2. number ^ number;

- Dharmendra January 26, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

XOR the number with itself.

You can do this in a language like Java or C# with a simple number ^ number;

The result of an XOR between two bits is only 1 when one, but not both, of the bits are 1.

Logically, you can see that if you XOR a number with itself, any 1 bits will go to zero because 1 ^ 1 = 0. Any bits that are 0 will stay zero, because 0 ^ 0 = 0. So any number XOR'd with itself is always 0.

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

Just calculate the number of set bits. These need to be flipped. I guess this would be a respectable answer.

- Nascent January 26, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

number & 0 is the expected answer

- Mahesh January 26, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

n & ~n

- Murali Mohan January 26, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Just return 0. Don't care of any inputs.

- gourahari.das January 28, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

XOR and AND : if using XOR then first check if number = 1 then input[i] ^ 1;
if using AND then directly input[i] & 0;

- Sameer Shukla January 28, 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