Pipeline Throughput Maximization Under Budget
Updated
Problem statement
You have a serial pipeline of n services. Service i has base throughput throughputs[i] and scaling cost costs[i].
You can scale service i by a non-negative whole number x. Its throughput then becomes throughputs[i] * (1 + x), and the cost for that service is x * costs[i].
The pipeline is serial, so its throughput is the minimum throughput among all services after scaling. You have a total budget to spend on scaling. Return the maximum pipeline throughput you can reach.
To reach a target throughput T, service i needs x = ceil(T / throughputs[i]) - 1 scale steps. If throughputs[i] ≥ T, it needs x = 0. The cost to reach T is the sum of x * costs[i] over all services. You can reach T when this cost is at most budget, and a larger T never costs less, so you can binary search on T.
Complete the function maximizePipelineThroughput in the editor.
maximizePipelineThroughput has the following parameters:
int[] throughputs: the base throughput of each serviceint[] costs: the cost of one scale step for each servicelong budget: the total scaling budget
The function returns a long: the maximum pipeline throughput.
Function
maximizePipelineThroughput(throughputs: int[], costs: int[], budget: long) → longExamples
Example 1
throughputs = [5, 2, 4]costs = [3, 10, 2]budget = 0return = 2With no budget, the pipeline throughput is the minimum base throughput, which is 2.
Example 2
throughputs = [5, 2, 4]costs = [3, 10, 2]budget = 20return = 4Binary search on target throughput T. For T=4: service 0 already has throughput 5>=4 (cost 0), service 1 needs ceil(4/2)-1=1 scale step (cost 1*10=10), service 2 already has throughput 4>=4 (cost 0). Total cost = 10 <= 20, so T=4 is achievable. For T=5: service 1 needs ceil(5/2)-1=2 steps (cost 20), service 2 needs ceil(5/4)-1=1 step (cost 2). Total cost = 22 > 20, so T=5 is not achievable. Therefore the maximum throughput is 4.
Constraints
1 ≤ n ≤ 2 * 105, wherenisthroughputs.lengthandcosts.length1 ≤ throughputs[i], costs[i] ≤ 1090 ≤ budget ≤ 1018- The answer fits in a
long(64-bit signed integer). - While you test a target, the total cost can grow much larger than a
long. Stop adding as soon as the total is abovebudget, or use a wider type.
More Uber Online Assessment questions
- Count Palindromic Ancestor PathsOA · Seen Aug 2026
- Jump Game with Prime-3 StepsOA · Seen Aug 2026
- Last Truck to Leave the LaneOA · Seen Jul 2026
- Chain of CommandOA · Seen Jul 2026
- Total Palindrome Substring CostOA · Seen Jun 2026
- Jump Game with Prime-Step RuleOA · Seen May 2026
- Balanced Prefix Sets in a PermutationOA · Seen Apr 2026
- Minimum Edge Reversals to Root a TreeOA · Seen Apr 2026
- Maximum Riders in CarOA · Seen Apr 2026
- Graph Palindrome QueriesOA · Seen Apr 2026
Similar questions at other companies
- Server Upgrade PlanningWells Fargo · OAWells Fargo interview questions
- Find Minimum TimeAlphaSense · OA
- Find Minimum TimeBlackRock · OABlackRock interview questions
- Maximize Pipeline Throughput Under a Scaling BudgetMicrosoft · OAMicrosoft interview questions
- Rock JumpingIMC Trading · OAIMC Trading interview questions
- Minimum Robot and Human Fulfillment TimeAmazon · OA
- Minimize Maximum Group DifferenceDRW · OADRW interview questions
- Array NullificationQRT · OA
- Minimum HeightSnowflake · OASnowflake interview questions
- Minimum-Cost Solar Rooftop AllocationDeloitte · OADeloitte interview questions