FastPrepRandom Pick with Weight Using Recorded Draws
Problems/Random Pick with Weight Using Recorded Draws

Random Pick with Weight Using Recorded Draws

Google logoGoogle● MediumFULLTIMENEW GRADPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The Google MLE onsite report says this task was like a well-known random-pick-with-weight problem but changed its context. The changed setup and the follow-up that allows only linear time are not shared. Here we use the basic fixed-weight index pick, cap input arrays at 2,000, and supply recorded uniform draws so grading is always the same. Our version is about 65% the same as the reported question.

You are given an array weights of positive integers and a sequence draws of recorded uniform random tickets. The weight at index i determines how many tickets select that index.

Let total be the sum of all weights. Tickets are integers from 0 through total - 1. Assign the first weights[0] tickets to index 0, the next weights[1] tickets to index 1, and so on. For each ticket, return its selected index. Keep the answers in the same order as draws.

The weights do not change between draws. If a ticket is sampled uniformly from this range, index i is selected with probability weights[i] / total. The input supplies each sampled ticket so the expected result is reproducible.

Function

pickIndices(weights: int[], draws: int[]) → int[]

Examples

Example 1

weights = [1,3]draws = [0,1,2,3]return = [0,1,1,1]

Ticket 0 belongs to index 0; tickets 1, 2, and 3 belong to index 1.

Example 2

weights = [2,1,2]draws = [0,1,2,3,4]return = [0,0,1,2,2]

The half-open ticket intervals are [0,2), [2,3), and [3,5).

Example 3

weights = [5]draws = [4,0,2]return = [0,0,0]

Every valid ticket chooses the only index.

Constraints

  • 1 <= weights.length <= 2000.
  • 1 <= weights[i] <= 10^5.
  • 1 <= draws.length <= 2000.
  • For every ticket t in draws, 0 <= t < total, where total is the sum of all weights.
  • total <= 2 * 10^8, so cumulative weights fit in a signed 32-bit integer.

More Google Onsite Interview questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Random Pick with Weight Using Recorded DrawsAmazon · ONSITE INTERVIEW
  • Multinomial Sampling with Distribution ChecksNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
  • Random Pick with Weight Using Recorded DrawsMeta · PHONE SCREENMeta interview questions
  • Totals from a Tiered Rate TableMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Koko Eating BananasTekion · ONSITE INTERVIEWTekion interview questions
  • Farthest Affordable Shop per QueryAdobe · ONSITE INTERVIEWAdobe interview questions
  • Good Ways to Split an ArraySalesforce · PHONE SCREENSalesforce interview questions
  • Minimum of a Convex FunctionRippling · PHONE SCREENRippling interview questions
  • Percentile and Boundary QueriesDatadog · PHONE SCREENDatadog interview questions
  • Longest Run of Ones After Flipping k ZerosC3.ai · PHONE SCREENC3.ai interview questions

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int[] pickIndices(int[] weights, int[] draws) {
        // Write your code here.
    }
}
Checking account…