Pregunta de entrevista de Amazon

coding question about weighted random number generator