Search⌘ K

DIY: Random Pick with Weight

Explore how to implement a weighted random index picker in Ruby, simulating Uber's driver allocation scenario. Understand how to convert weights to probabilities and return an index according to its weight. This lesson helps build skills to solve real-world weighted selection problems common in coding interviews.

Problem statement

You are given an array of positive integers, w, where w[i] describes the weight of the ithi{th} ...