Expedia Interview Question for Software Engineer / Developers






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

Pretty simple solution, may not be the most efficient though

int bitCountDiff( byte x ) {
int count = 0;
do {
count += (x & 1) ;
x >>= 1;
}
while(x != 0);
return count;
}

- Jimmy December 10, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Its an infinite loop for -1.

Typically we think that num >> 1 is same as num /2 and num << 1 is same as num *2. But thats not 100% true for -ve numbers. -1/2 is 0 but -1 >> 1 is still -1.

In Jimmy's code, replace x >>=1; to x /=2; should solve infinite loop for -ve numbers.

- EX-MSFT April 14, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

or you can read in an unsigned int

- ST May 10, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int i =42;
int cnt=0;
while(i!=0){
i = i & (i-1);
cnt++;
}

System.out.println(cnt); // =3 for i =42 = 0010 1010
Using Bit wise AND property.

- Anonymous November 02, 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