Solving Random Pick with Weight in go. Please try yourself first to solve the problem and submit your implementation to LeetCode before looking into solution.

Problem Description

Note:

  1. 1 <= w.length <= 10000
  2. 1 <= w[i] <= 10^5

Example 1:

Input: 
["Solution","pickIndex"]
[[[1]],[]]
Output: [null,0]

Example 2:

Input: 
["Solution","pickIndex","pickIndex","pickIndex","pickIndex","pickIndex"]
[[[1,3]],[],[],[],[],[]]
Output: [null,0,1,1,1,0]

Explanation of Input Syntax:

  1. 1 <= w.length <= 10000
  2. 1 <= w[i] <= 10^5

See the full details of the problem Random Pick with Weight at LeetCode

Originally posted at: @github.com/halfrost/LeetCode-Go