LeetCode MEDIUM 528 Random Pick with Weight Summary
Generated by Codex with GPT-5
Quick facts
- Difficulty:
MEDIUM - Problem: Random Pick with Weight
- Main tags:
Array,Prefix Sum,Binary Search,Randomized
What the problem is really asking
The class receives an array of positive weights, where w[i] describes how likely index i should be picked. Calling pickIndex() should return one index at random, but not uniformly. Index i should be returned with probability: