All Problems

Random Pick with Weight

MediumarrayExpected: O(log n) time, O(n) spaceInterview Context
binary-searchprefix-sum

Problem

Given an array of positive integers w, implement pickIndex() that randomly picks an index in proportion to its weight.

Loading...