Weighted Lottery Winners
Problem statement
Use the supplied deterministic tickets to simulate weighted draws without replacement. For draw d, map tickets[d] into the current total weight, select by zero-based cumulative weight, then remove that bidder.
Function
weightedWinners(bids: int[], tickets: int[], k: int) → int[]Examples
Example 1
bids = [1,3,6]tickets = [0,0]k = 2return = [0,1]Deterministic weighted draw sequence 1 exercises shrinking totals and removal.
Example 2
bids = [1,3,6]tickets = [9,0]k = 2return = [2,0]Deterministic weighted draw sequence 2 exercises shrinking totals and removal.
Constraints
1 <= bids.length <= 20000 <= bids[i] <= 100and at leastkbids are positive.0 <= k <= min(bids.length,tickets.length)- Tickets are nonnegative integers.