## Qualcomm Interview Question for Software Engineer / Developers

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

``````while(num)
{
ctr++;
num = num & (num-1);
}``````

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

for (int s=0,int n=0; n; n>>=1)
s+=n&1;

return s;

Or use kernighan's method for less iteration

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

Hey dude,
I knew what you mean and it seems a good approach.

you returned s which is defined in for condition.
One more n is assigned 0 but you used n directly.
it must be negative point in the interview.

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

int nos_of_ones(int n){
int count = 0;
while (n!=0){
if (n&1){
count++;
}
n>>1;
}
return (count);
}

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

int nos_of_ones(int n){
int count = 0;
while (n!=0){
if (n&1){
count++;
}
n>>1;
}
return (count);
}

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

int nos_of_ones(int n){
int count = 0;
while (n!=0){
if (n&1){
count++;
}
n>>1;
}
return (count);
}

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

int nCount=0/*number of binary 1's*/, i, input = 98/*some random number*/;
for(i=0; i<8*sizeof(input);i++)
{
if(input & (1<<i))
nCount++
}

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

``````count(int n)
{
int r,count=0;
while(n>0)
{
r=n%2;
if(r==1) count++;
n/=2;
}
return count;}``````

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

is it a must that we use bitwise operators? the above soln works too with O(n) complexity, n is the number of bits in binary rep.

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

``````int num_0 = 0;
while (n) {
num_0 ++;
n &= n-1;
}``````

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

Is it possible that we can optimize this solution by casting the number as a series of bytes? Using this we can iterate over each byte and can possibly optimize by skipping over bytes that are zero and run the same algo as mentioned before on each byte.

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.