NeetCode #291LC-528MediumBinary Search
← Back to All Problems

#291 · #528 · Random Pick with Weight(按权重随机选择)

📌 Problem Statement & Constraints

You are given a 0-indexed array of positive integers w where w[i] describes the weight of index i. Implement pickIndex() which returns an index chosen at random with probability proportional to its weight. Constraints: 1 <= w.length <= 10^4, 1 <= w[i] <= 10^5; at most 10^4 calls.
🔒

Sign In to Unlock Full Solutions for All 973 Problems

Sign in to access step-by-step logic, benchmark Python3 code, complexity breakdown, and offline export!