Microsoft Interview Question for Software Engineer in Tests






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

I guess the 1st solution is the best becoz it shifts only one digit left => least prone to overflow...while doing num<<2 shifts the digits 2 bits...which unnecessarily increases the probability of overflow

- Nitesh October 02, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

x >> 1 = x/2
x << 1 = x*2 So,

x/2 + x + 2x = 7x/2 = 3.5x

- Laks September 26, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

One more solution:

(num<<3 - num)>>1

This is multiply the number by 7 and divide by 2

- Aditya September 27, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Why not (num << 2) - (num >> 1)

- Anonymous October 01, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

anyone agree on Nitesh? it seems right..

- shoushou January 13, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

well the Qs. should be to multiply by 3.5 without using any arithmetic i.e. +,-,/,*
operator.Only then its challenging

- code_pro March 15, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

x>>1 => x/2 only when x is power of 2.
Example:
if x=3(in decimal)=0011(in binary)
then x>>1 = 0001(in binary) =1(decimal)

do u think 3.5x=3.5*3 is same as (3>>1)+3+(3<<1)

- buckCherry May 13, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Great!

- Interested July 29, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

kausik is right. x>>1 only meaning frul when x is power of 2.

Plus!! I believe this question was asked deliberately vague. I don't think this question is to ask multiplying w/o using any arithmetic, but to ask how you would handle integer type to correctly represent x3.5 situation. rounding to the integer is not acceptable..!

- sungmj July 24, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 0 vote

can some one please explain question in detail?
And what "(x>>1)+x+(x<<1)" solution is?

- Raj September 26, 2008 | 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