2024-08-24 02:12
요즘은 잘 안묻는 유명한 코딩 인터뷰 문제.
An array is given as an iterator with .has_next() and .next() methods. E.g.
# iterating the array iterator
while data.has_next():
print(data.next())
where .has_next() returns True if there is a next element to read, otherwise False, and .next() yields the next array element if .has_next() is true.
Write a function that randomly and fairly samples k elements from this array given as an iterator.