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);
}

- Anonymous November 20, 2009 | Flag Reply
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

- guest October 27, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hey dude,
I knew what you mean and it seems a good approach.
But look at your code.

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.

- Anonymous October 31, 2009 | Flag
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);
}

- Anonymous November 03, 2009 | Flag Reply
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);
}

- Anonymous November 03, 2009 | Flag Reply
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);
}

- Anonymous November 03, 2009 | Flag Reply
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++
}

- Rajesh Amrutha December 15, 2009 | Flag Reply
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;}

- Anonymous January 05, 2010 | Flag Reply
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.

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

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

- Anonymous January 16, 2010 | Flag Reply
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.

- Rahul Balakavi January 21, 2013 | 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