Amazon Interview Question for Software Engineer / Developers






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

int multBy7(unsigned int n)
{
return ((n<<3) - n);
}

- Anonymous March 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

do we have anything better than this

- hary March 11, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

What do u mean by better?

- James Bond March 11, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

If u shift the bits 3 times, u r multiplying the number by 2^3 = 8. so now subtract the number by itself to multiply it by 7 times.

- Ranganath March 12, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

perfect

- tetura March 12, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

just perfect... simple logic.... efficient use...!!!!

- rhino March 20, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Respect!

- gaurav June 14, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can someone explain the logic behind this?

- Anonymous March 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Say you have to multiply 'a' by 'b'.
Find a smallest number 'c' which is greater than 'b' and is a power of 2 (you would be interested in this because you would want to shift bits - efficient method.) so if c = 2^k then a.c = (a << k) right shifting 'a' by k bits.

Now, we know that a.c is greater than a.b, so we would want to subtract the difference [(c-b).n] off the *product*,

simply put: b = ( c - delta ) -> a.b = (c-delta) . a -> a.b = a.c - a.delta

[delta is known in all cases since you pick 'c' and 'b' is already given]

- TheRandomGuy March 13, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

explanation for the first soln....
logic :
7*x = 8*x - x
7*x = (x<<3) - x

as x<<3 = x*(2^3);
case closed ;)

- rhino March 20, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

See geeksforgeeks.org/?p=532

- Anonymous March 11, 2010 | 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