由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - need help on GS inverview question
相关主题
关于phone inverview非常不理解这HR是怎么想的
onsite inverview要带什么东西吗?贴个刚才的电话面试题
One onsite inverview question[合集] 2006年底石油公司面试 (经验 游记) zz
another GS inverview question, help!一个概率+编程题。
电话中写 code,不是给做弊的机会吗ms onsite 杯具,攒rp发面经
请问A家Research Scientist Internship Phone Inverview面经
上周五Comcast onsite,求祝福外加简要流程Google电面
请问onsite inverview后多久reference check,Software Developers Needed (转载)
相关话题的讨论汇总
话题: line话题: gs话题: inverview话题: when话题: need
进入JobHunting版参与讨论
1 (共1页)
h********r
发帖数: 30
1
if you have a large file, hundreds of millions of lines that I need to
select a random line from. How to do it through reads through the file once?
I have no clue how to do it....
x*****p
发帖数: 1707
2
First, read line by line
When you read the first line, keep it in the memory;
When you read the second line, you have 1/2 chance to replace the line in
the memory.
When you read the n-th line, you have 1/n chance to replace the line in
the
memory.
If you totally go through m lines, then for any line, say the k-th line,
the
chance that it can be selected in the memory is
1/k * (1 - 1/(k+1)) * ... * (1 - 1/m) = 1/m
So it is a real random choice, evenly distributed.
g*******s
发帖数: 490
3
Reservoir sampling
h********r
发帖数: 30
4
great, thanks a lot!

【在 x*****p 的大作中提到】
: First, read line by line
: When you read the first line, keep it in the memory;
: When you read the second line, you have 1/2 chance to replace the line in
: the memory.
: When you read the n-th line, you have 1/n chance to replace the line in
: the
: memory.
: If you totally go through m lines, then for any line, say the k-th line,
: the
: chance that it can be selected in the memory is

1 (共1页)
进入JobHunting版参与讨论
相关主题
Software Developers Needed (转载)电话中写 code,不是给做弊的机会吗
问两道Google面试题请问A家Research Scientist Internship Phone Inverview
问一道Amazon的老题上周五Comcast onsite,求祝福外加简要流程
Senior Reservoir Simulation--Enhanced Recovery Engineer请问onsite inverview后多久reference check,
关于phone inverview非常不理解这HR是怎么想的
onsite inverview要带什么东西吗?贴个刚才的电话面试题
One onsite inverview question[合集] 2006年底石油公司面试 (经验 游记) zz
another GS inverview question, help!一个概率+编程题。
相关话题的讨论汇总
话题: line话题: gs话题: inverview话题: when话题: need