Interview Query

Multimodal Sample

10
Have you seen this question before?

Write a function for sampling from a multimodal distribution. 

Inputs are keys (i.e. green, red, blue), weights (i.e. 2, 3, 5.5), and the number of samples drawn from the distribution. The output should return the keys of the samples. 

Example: 

Input:

keys = ['green', 'red', 'blue']
weights = [1, 10, 2]
n = 5
sample_multimodal(keys, weights, n)

Output

['blue', 'red', 'red', 'green', 'red']
Next question: Merge N Sorted Lists
.....
Python 3.9.6
Loading editor
Use Shift + Enter to run code