FastPrepWeighted Lottery Winners
Problems/Weighted Lottery Winners

Weighted Lottery Winners

Amazon logoAmazon● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Amazon full-time onsite interview. The report describes picking k different winners with a chance in proportion to integer bids. It does not give everything needed to run it, so we set these fixed rules. You receive fixed non-negative tickets. Each ticket is taken modulo the sum of the remaining positive bids. The winner is the first one whose running total of bids is above that value. That winner is removed. You return min(k, n) indices in the order they were drawn.

Run a lottery that picks k different winners from a row of bidders. bids holds each bidder's bid, and a bigger bid gives a bigger share of each draw. Instead of random numbers, the draws use the given tickets, in order.

Draw d uses the ticket tickets[d] and works like this:

  1. Add up the bids of the bidders still in the lottery.
  2. Take the remainder of tickets[d] divided by that total.
  3. Walk through the remaining bidders from the left. Keep a running total of their bids, starting from zero.
  4. The first bidder whose running total goes above the remainder wins. Remove that bidder before the next draw.

Run k draws. Return the winners' indices in bids, in the order they were drawn.

Function

weightedWinners(bids: int[], tickets: int[], k: int) → int[]

Examples

Example 1

bids = [1,3,6]tickets = [0,0]k = 2return = [0,1]

In the first draw, the bids add up to ten. The first ticket is zero, so the remainder is zero. The first bidder's bid, 1, is already above zero, so the first bidder wins and is removed. In the second draw, the bids left add up to nine, and the second ticket is also zero. Now the first bidder still in the lottery is the second bidder, and its bid is above zero, so it wins. The winners, in draw order, are the first bidder and then the second bidder.

Example 2

bids = [1,3,6]tickets = [9,0]k = 2return = [2,0]

In the first draw, the bids add up to ten, and the first ticket is nine, so the remainder is nine. The running totals are one, four and ten. Ten is the first total above nine, so the third bidder wins and is removed. Its index is 2. In the second draw, the bids left add up to four, and the second ticket is zero. The first bidder's running total is already above zero, so the first bidder wins. The winners, in draw order, are the third bidder and then the first bidder.

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 Onsite Interview questions

  • Assign Escalations to TeamsONSITE INTERVIEW · Seen Nov 2026
  • Best Time to Buy and Sell StockONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Maximum Earnings Across WarehousesONSITE INTERVIEW · Seen Nov 2026
  • Priority Message BufferONSITE INTERVIEW · Seen Nov 2026
  • Search in a Rotated Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent ElementsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Maximal SquareONSITE INTERVIEW · Seen Nov 2026
  • Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Calculate Server Shutdown PenaltyStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
  • Instrument Stack Language JumpsJane Street · PHONE SCREENJane Street interview questions
  • Schedule Buffered Video PlaybackNuro · PHONE SCREENNuro interview questions
  • Hall of Shifting TilesAdobe · OAAdobe interview questions
  • Prefix Scores With the Running MaximumC3.ai · OAC3.ai interview questions
  • Online No-Intercept Linear RegressionTwo Sigma · OATwo Sigma interview questions
  • Wallet Balance on a Selected DayBharatPe · PHONE SCREEN
  • Array Challenge (QR Intern)Akuna Capital · OAAkuna Capital interview questions
  • Range Negation UpdatesJP Morgan Chase · OAJP Morgan Chase interview questions
  • Data UpdatesExpedia · OAExpedia interview questions

Interview reports that mention this question

  • Amazon Experienced Hire OA and Interviews: 21 Experiences

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
See Amazon hiring insights
Saved
class Solution {
    public int[] weightedWinners(int[] bids, int[] tickets, int k) {
      // Write your code here.
    }

}
Checking account…