Minimum Redistribution Cost
Updated
Problem statement
There are n warehouses arranged in a circle. Warehouse i initially stores products[i] items.
You may redistribute items around the circle, but all moved items must travel in one fixed direction: either clockwise or counter-clockwise. Moving one item across one edge costs 1.
Return the minimum total cost needed to make every warehouse contain the same number of products. You may choose the better of the two directions.
Function
getMinimumRedistributionCost(products: int[]) → long Complete getMinimumRedistributionCost.
int products[n]: product counts around the circle
Returns long: the minimum redistribution cost.
Examples
Example 1
products = [1,11,1,1,1]return = 20The average is 3. The extra 8 products at the second warehouse must fill deficits of 2 at four other warehouses. In either direction, the total edge-crossing cost is 20.
Example 2
products = [0,6,0]return = 6The average is 2. Four items move out of the middle warehouse: two cross one edge and two cross two edges.
Constraints
- 1 <= products.length <= 10^5
- 0 <= products[i] <= 10^9
- The total number of products is divisible by products.length.
More Amazon Online Assessment questions
- Get Smallest Base SegmentOA · Seen Nov 2026
- Minimum Cost of Left and Right PropagationOA · Seen Nov 2026
- Minimum Grid InconvenienceOA · Seen Nov 2026
- Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
- Maximize Shipment Order by Sorting One WindowOA · Seen Nov 2026
- Maximum Equal-Bit Pairs in a SubsequenceOA · Seen Nov 2026
- First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
- Two SumOA · PHONE SCREEN · Seen Nov 2026
- Minimum Merge ConflictsOA · Seen Nov 2026
- Shopping Cart BillingOA · Seen Nov 2026
Similar questions at other companies
- Minimum Cost K-Capable ModelsMicrosoft · OAMicrosoft interview questions
- Optimal TransferSnowflake · OASnowflake interview questions
- Gas Station Loop StartNutanix · OANutanix interview questions
- Redistribute MegaseedsRubrik · OARubrik interview questions
- Maximum Distinct Items Within a BudgetAdobe · OAAdobe interview questions
- Minimum AmountBelvedere Trading · OA
- Focus on Efficiency (2024 NG)Google · OAGoogle interview questions
- Running Through Walls with Limited EnergyScale AI · OAScale AI interview questions
- Make the Array PositiveAtlassian · OAAtlassian interview questions
- Maximize Compatible Car RidersUber Freight · PHONE SCREEN · ONSITE INTERVIEWUber Freight interview questions
Amazon interview experiences
- Amazon SWE OA with AI Coding: 1 Experience
- Amazon SWE Intern Phone Screen Interview Experience: 1 Experience
- Amazon New Grad SDE I OA and Virtual Onsite: 1 Experience
- Amazon BIE Intern SQL and Interview Questions: 17 Experiences
- Amazon Experienced SWE AI-Assisted Debugging OA: 1 Experience
- Amazon SDE II (L5) Interview Questions: 5 Experiences