Pergunta de entrevista da empresa Yelp

A question on probabilities. When you select a random index from the array, the probability of the element that is printed should be based on its weight