Microsoft Interview Question for Software Engineer / Developers


Team: bing
Country: India
Interview Type: In-Person




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

Assuming that the bits from the stream are treated as added at the least-significant (right) end:

bool divisibleBy3(bool next_bit)
{
  static int remainder = 0;
  remainder = ((remainder * 2) + (next_bit ? 1 : 0)) % 3;
  return (remainder == 0);
}

- YG March 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Very good solution!

- Senthil May 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Problem with the code is.. "Int" will overflow after 32 bits.

- Anon November 05, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

maintain two sum of even and odd position bits with modulo 3 and the moment difference become 0 number is divisible by 3.

- Anonymous April 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Count the number of bits set in the number
If it is even then divisible by 3 else not

- DashDash April 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what do u mean by bits set?

- Anonymous June 12, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

That's clearly not a valid solution. Counterexamples: 17 (2 bits set, not divisible by 3), 42 (3 bits set, divisible by 3).

- Anonymous June 16, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int bit;
int state = 0; // 0 : divisible, 1: remainder is 1, 2: remainder is 2

while ( (bit = getNextBit()) != NULL)
{
switch (state)
{
case 0:
if (bit == 0) state = 0; // remain as divisible
else state = 1; // change state to "remainder is 1"
break;
case 1:
if (bit == 0) state = 2;
else state = 0;
break;
case 2:
if (bit == 0) state = 1;
else state = 2;
break;
} // end of switch
} end of while.

- Anonymous May 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

In real implementation is not possible. But from logic point of view we can use exponential algorithm like power(3,k)%3 == 0 it will show that it is divided by 3 with complexity nlog(n/2).

- Anonymous March 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Try building a finite state automata.

- Mohit March 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Count the number of bits set in the number
If it is even then divisible by 3 else not

- DashDash April 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

keep adding the digits that are entered .. if the summation is divisible by 3 then its a multiple of 3 otherwise not

- jane March 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Jane tere ko toh me binaa condom ke raand ki maafik chodu ....
teraa contact details de

- MS DHONI May 15, 2012 | Flag


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