Microsoft Interview Question Developer Program Engineers


Country: India


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

without parallel processing naive method is :-
simply % 2 to increase the count of 1 and then divide by 2(basically checking the last bit of the no till Most significant bit comes to last bit)

while(no!=0)
{
if(no%2 == 1)count++;
no = no/2;
}

With parallel processing ideal logic must be divide total no bits that your no can have into different set and parallel process each one of them

for eg if you have a 64 bit no divide 64 bit into 8 set of 8 bits

no1 = no&(2^8-1 <<0)
no2 = no&((2^8-1) << 8)
no3 = no&((2^801) << 16).
.
.
so on till no8

now for each no calculate separately in each processor the no of 1's and then add them.
..

- krbchd on July 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

one correctio:- n(typ)
no3 must be :- no&((2^8 -1)<<16)

generic
no x = no&((2^8 -1)<<8*(x-1))

- krbhcd on July 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

given that number is loo large like "234592379873427345723452943852983745982345634" in the form of string or something else.
so how can you do no%2, as this not int / long...
you need to extract first 8 characters and find the #of 1's in it and then next 8 characters and so on...

- Anonymous on July 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 vote

count(int num)
{ int counter=0;

while(num>0)
{
num=num & num-1;
counter++;
}

}

- amnesiac on August 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Wht about hadoop ? even GB's of data

- Tarun Aggarwal on August 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

#include<iostream>

using namespace std;

int main()
{
int n,count=0;
cin>>n;
while(n!=0)
{
count++;
n=n&(n-1);
// cout<<n<<endl;
}

cout<<count;
return(0);
}

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

what is complexity of this code.

- blake on August 17, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Number of one' s present in 'n'

- sumeet.kukkar on January 26, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

then how to make parallel call?

- Ravinth on July 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

count the length create two or more start points like start comparing from 0th index to forwrd and nth index backward stop whre indexes r equal..(this way many start points can be created and can be executed simultaneously in threads)
run using thread to speed up

- naruto on July 30, 2012 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book walking you through 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