Search⌘ K
AI Features

Random Pick with Weight

Understand how to create a function that randomly selects an index from a weighted array with probabilities proportional to weights. Explore using modified binary search to achieve efficient weighted random selection, and practice implementing this approach for coding interviews.

Statement

You’re given an array of positive integers, weights, where weights[i] is the weight of the ithi^{th} ...