Qualcomm Interview Question for Software Engineer / Developers






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

int num /*Given 16 bit integer*/
int count = 0; /*gives total no. of 1's in num*/
for(i=0;i<16;i++)
{
if((num>>i) && 1)
{
count++;
}
}

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

Most optimal solution would be -

int num /* given 16 bit integer */
int count = 0; /* total no. of 1's in num */
while (num & (num-1)) {
count++;
num = num & (num-1);
}
print(++count);

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

Obviously corner cases like if num == 0 needs to be taken care.

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

why ++count after while loop ?
thats unnecessary

- n00bCod3R March 27, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

n is any number.

void numberofones (int n)
{
int i=0;

while (n)
{
n = n&(n-1);
i++;
};
printf (" Number of ones : %d\n",i);

}

- sumeet4linux April 16, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
int main()
{
short a = 65535;
int i=0,count=0;

for(i=0;i<16;i++)
{
if(a & (1<<i))
count ++;
}
printf("\nCount:%d",count);
return 0;
}

- Sam September 18, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The number of 1s in the given number can be found by right shifting the binary number of the given integer and counting the number of 1s if it satisfies the condition that (n&1 == 1) else it is not a set bit.

Implementation:

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

}

- swapnilkant11 July 22, 2019 | 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