Sample a Number from a Stream Proportional to Its Frequency
Read a stream of non-negative integers, stopping when a zero is received. After the stream ends, return a random number from the stream such that each number is selected with probability proportional to how often it appeared (i.e., matching the empirical frequency distribution of the stream).
Asked at:
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
All Regions
Early September, 2024
Mid-level
Given a stream of non-negative integers until receiving a zero, print a number from the stream with the distribution of the numbers in the stream.
Hello Interview Premium
Your account is free and you can post anonymously if you choose.