Size-Weighted Random Server Picks
Updated
Problem statement
A service sends each incoming job to one of its servers. sizes[i] is the size of server i. The server for a job is picked at random, and a server's chance must be proportional to its size. For example, with sizes [4, 1], server 0 should get about 4 out of every 5 jobs.
To make the answer checkable, the random numbers are already drawn for you. Let total be the sum of all sizes. The whole numbers 0 to total - 1 are split into blocks, one per server, in the order the servers are given:
- server
0owns the firstsizes[0]numbers,0tosizes[0] - 1; - server
1owns the nextsizes[1]numbers; - and so on, so the last server owns the numbers up to
total - 1.
draws[j] is the random number drawn for job j. Return an array whose j-th value is the index of the server that owns draws[j].
Function
pickServers(sizes: int[], draws: int[]) → int[]Examples
Example 1
sizes = [4,1]draws = [0,4,1,2,3]return = [0,1,0,0,0]Server 0 owns the numbers 0 to 3, and server 1 owns 4. So the draws 0, 4, 1, 2, 3 go to servers 0, 1, 0, 0, 0.
Server 0 is 4 times as big, and over many random draws it gets about 4 out of every 5 jobs.
Example 2
sizes = [2,5,3]draws = [9,0,2,6,7,1]return = [2,0,1,1,2,0]The total is 10. Server 0 owns 0 to 1, server 1 owns 2 to 6, and server 2 owns 7 to 9.
So 9 goes to server 2, 0 to server 0, 2 and 6 to server 1, 7 to server 2, and 1 to server 0.
Example 3
sizes = [10]draws = [7,0]return = [0,0]With one server, every job goes to server 0.
Constraints
1 <= sizes.length <= 10001 <= sizes[i] <= 10^61 <= draws.length <= 10000 <= draws[j] < total, wheretotalis the sum of allsizes[i]
More DocuSign Online Assessment questions
- Max Sum With No Two Adjacent PicksOA · Seen Apr 2026
- Max Sum With No Two Adjacent Picks on a CircleOA · Seen Apr 2026
- Beautiful Number OrderingsOA · Seen Feb 2026
- Grid Path With the Most ClearanceOA · Seen May 2025
- Vehicle Mixes for a Wheel TotalOA · Seen May 2025
- Count Sales Rung Up at the Wrong PriceOA · Seen Feb 2021
- Most Disjoint Intervals From Starts and DurationsOA · Seen Feb 2021
- Fewest Fountains to Water the GardenOA · Seen Feb 2021
- Lowest Start That Keeps Running Totals PositiveOA · Seen Feb 2021
- Fewest Student Groups Within a Level GapOA · Seen Nov 2020
Similar questions at other companies
- Choose ContainersIMC Trading · OAIMC Trading interview questions
- Minimum Size Subarray SumMicrosoft · OAMicrosoft interview questions
- Calculate Total Distance TravelledAmazon · OA
- TikTok Metrics AnalysisTikTok · OATikTok interview questions
- Load BalancingMathWorks · OAMathWorks interview questions
- Largest Square Sub-Grid Within a Sum LimitC3.ai · OAC3.ai interview questions
- Maximum Distinct Items Within a BudgetAdobe · OAAdobe interview questions
- Calculating QuantilesIndeed · OAIndeed interview questions
- Count Lamps Lighting Each PointCapital One · OACapital One interview questions
- Maximum Non-Decreasing Array LengthVisa · OAVisa interview questions