FastPrepWeighted Lottery Winners

Weighted Lottery Winners

Amazon logoAmazon● MediumFULLTIMEONSITE INTERVIEW
Learn

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 <= 2000
  • 0 <= bids[i] <= 100 and at least k bids are positive.
  • 0 <= k <= min(bids.length,tickets.length)
  • Tickets are nonnegative integers.

More Amazon problems

See Amazon hiring insights
public int[] weightedWinners(int[] bids, int[] tickets, int k) {
  // Write your code here.
}
bids[1,3,6]
tickets[0,0]
k2
expected[0,1]
Checking account…