AlgoMaster Logo

Random Pick with Weight

weights=[1, 3, 2, 4],target=7
0 / 12
algomaster.io
Step:Start: build the prefix sum, then linearly scan for the target bucket