Google Interview Question for Software Engineer / Developers






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

Google really seems to be fond of this question. This has appeared many times on many sites, including this one.

bing "reservoir sampling" for the answer.

- LOLer July 17, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I would rather google it, thank you. Sorry for straying away from the question though.

- Anonymous July 18, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Lookup humor while you are at it.

- BFD July 18, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I did. It said you'r smart!! haha !!

- Anonymous July 20, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Seems like google has it's flaws too.

- BFD July 20, 2009 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

here is a short explanation: at any moment, if you have seen K records so far, each record should have a probability of 1/K to be chosen.

Recursively, when you see the Kth record, you pick it with 1/K probability, otherwise you just keep your previous pick.

- interviewtomorrow September 15, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

vector<int> data;
int i;

data is the list of records. we choose a sample of k records from data in a single pass.

vector<int> sample(data.begin(),data.begin()+k);

data.end() be a marker to the end of list data .

int random;

for(i=k;i!=data.end();i++)
{

random=rand()%(k+1234);

if(random<k)
sample[random]=data[i];

}

- reservoir sampling July 26, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

binging/googling dint give me simple/understandable definition. can somene plz explain this reservior sampling thing. i m not able for figure out much.

- pinker August 06, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

yahoo search returned reservoir sampling ... but any built in rand guarantees a "uniform distribution" if the seed is not pre-set.

- test September 25, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Should you google every problem you cannot handle at your first glance, you never get improved. Common, try solve it on yourself before you rush to ask google, wiki, yahoo...

BTW, this one is so easy, assuming you know basic probability stuff.

- Anonymous September 29, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Say line count is a. For a=1, return the line read since prob is 1 and store it in variable b. For a=2 and thereafter, for every line read, find a random number between 0 and 1. If it lies between 0 and a-1/a, then return the new line and store it in variable b. If it lies between a-1/a and 1, then return the line previously stored in a.
The idea is that prob of line 1 is 1, 2 is (1 * 1/2), 3 is (1 * 1/2 * 2/3) and so on

- Metta August 27, 2010 | 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