Minimize Total Time
Updated
Problem statement
You are given two integer arrays:
int[] multiples: the multipliers available in the shopint[] prices: the corresponding prices for each multiplier
Both arrays have the same length n, and the i-th multiplier (multiples[i]) costs prices[i] coins to purchase.
You start with:
- 0 coins
- A base gain rate of 1 coin per second
When you purchase a multiplier, your coin gain rate is multiplied by that value. For example:
- Start: gain = 1x
- Buy 3x -> gain becomes 3x
- Buy 4x -> gain becomes 3 × 4 = 12x
You can only make purchases when you have enough coins to afford the multiplier.
Your goal is to purchase all the multipliers, in some order, such that the total time taken to finish all purchases is minimized.
Function
minimizeTotalTime(multiples: int[], prices: int[]) → int[]
Complete the function minimizeTotalTime in the editor.
minimizeTotalTime has the following parameters:
int[] multiples: an array of multipliers available in the shopint[] prices: an array of corresponding prices for each multiplier
Returns
int[]: an array of indices representing the order in which to purchase the multipliers to minimize the total time
Examples
Example 1
multiples = [3, 100, 30]prices = [5, 30, 15]return = [0, 2, 1][0, 2, 1] Buy 3x, then 30x, then 100x
Constraints
:O
More Google Onsite Interview questions
- 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
- Route Pattern MatcherPHONE SCREEN · ONSITE 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
- Timed Task ManagementInstacart · ONSITE INTERVIEWInstacart interview questions
- Minimum Refueling StopsUber · ONSITE INTERVIEWUber interview questions
- Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
- Minimum Station Tracks for a Train ScheduleBNSF Railway · ONSITE INTERVIEWBNSF Railway interview questions
- Minimum Railway PlatformsMakeMyTrip.com · ONSITE INTERVIEWMakeMyTrip.com interview questions
- Reduce Array Size to At Most HalfMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Maximize Monsters DefeatedSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Select K Paired Indices for Maximum ScoreAmazon · ONSITE INTERVIEW
- Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
- Minimum Removals for Non-Overlapping IntervalsByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions