Interview Query

Random Number

Start Timer

0:00:00

Upvote
0
Downvote
Save question
Mark as completed
View comments (11)
Next question

Given a stream of numbers, select a random number from the stream with equal probability and O(1)O(1) space in selection.

Input:

def random_number(x, y=0, count=1):
    pass
  • x is the new value from the stream.
  • y is the previously selected value.
  • count is the size of the stream.
.
.
.
.
.


Comments

Loading comments..