Amazon Interview Question for Development Support Engineers






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

#include<stdio.h>
#include<conio.h>
int main()
{
int count=0;
int x=6;
for(int i=0;i<8;i++)
{
count+=(x%2==0)?0:1;
x=x/2;
}
printf("COUNT :%d",count);
getch();
return 0;
}

- Sanjeev Kumar Sawargi March 08, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

X%2 always results in 0 or 1 need not assign explicitly.

- RAJ March 27, 2007 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

is the question no of 1 bits in a number... so for 5 which is 101 the answer is 2..but this does not work

- Anonymous April 01, 2007 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

It does work for 5
1st Pass: x = 5 and 5%2 = 1 so count = 1
2nd Pass: x = 2 and 2%2 = 0 so count = 1
3rd Pass: x = 1 and 1%2 = 1 so count = 2

So the solution is correct and will work for all the numbers.

- AD May 12, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int setbitcount(unsigned int u) {
int count = 0;
for(; u; u &= u-1)
count++;
return count;
}

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

assume number as num

count =0;
while(num != 0)
{
 count += num&1;
 num >>>= 1; 
}

- suria November 04, 2012 | 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