刚电面完,上来发面经,面试的是一个国人nice大哥,看linkedin简历秒我一百条街。
。。:
题目是:
Given an array or list of N elements. Return an array of K elements, with
each element in N has the exactly same chance to appear in the result, and
at certain position in the result. K<=N.
可以使用Math.Random()
Follow up是问时间和空间复杂度,然后问如果不是list,是一个stream list的话该怎
么做,时间和空间复杂度又是什么。
http://en.wikipedia.org/wiki/Reservoir_sampling
No comments:
Post a Comment