Uber Interview Questions: Weighted Random Numbers
Let me give you an example. Suppose we have 3 elements with their weights: A (1), B (1) and C (2). The function should return A with probability 25%, B with 25% and C with 50% based on the weights.
The answer is not obvious, but it's not too hard to think. Also, writing bug-free code would fail majority candidates. This is really the perfect question for coding interviews.
If you haven't solved this problem before, I'll give you 20min for both thinking and coding. Please try to solve it before reading the analysis below.
Read full article from Uber Interview Questions: Weighted Random Numbers
No comments:
Post a Comment