## Linkedin Interview Question for Software Engineer / Developers

Country: United States
Interview Type: Phone Interview

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

``````int integralPartOfLog(unsigned int n)
{

int ret = 0;

while (n > 0) {
n = n>>1;
ret++;
}

return ret-1;
}``````

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

This won't work for little/big endian machines both.

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

I think that's the most obvious way of solving the question.
graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious

@Game programmer -- what's wrong with that code?

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

That's the most obvious solution to the problem. This also states that
graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious
@Game programmer -- what's wrong with it?

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

``````int log2(int a)
{
int n=0;
while(a>1)
{
a>>=1;
n++;
}
return n;
}``````

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

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

I think we can not assume n is integer?

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

hi can you please share the reason behind above being a very bad code. What is wrong with that code? I too came up with a similar solution so I would like to know, where are we going wrong?

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

he's probably just a troll

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

Given a number
n = 2^m + x1*2^(m-1) + ...... xm*2^0 + (x(m+1))*2^-1 + ......
Must have
2^m <= n < 2^(m+1)
So
m <= log(2)n < m+1

m is the digit that the highest 1 appears in binary of n no matter n is integer or float.

By the way, Bitwise seems not apply to float in the scope of C/C++. I'm wondering the question implies we should only focus on integers.

You such a bad interviewer and hopefully the interviewee wasn't going to work with you as well.

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.

### 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.