FastPrepMinimum Redistribution Cost
Problems/Minimum Redistribution Cost

Minimum Redistribution Cost

Amazon logoAmazon● MediumOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: This came from real Amazon OA reports. The original reports shared the circular redistribution rule and a worked sample; FastPrep filled in the runnable function format and one extra practice example so you can try it here. Estimated match rate: 90-95% for the core task, 70-80% for exact wording and runner details. If you find a fuller version, feel free to let us know and we will update it.

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 = 20

The 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 = 6

The 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 problems

  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
See Amazon hiring insights
Saved
public long getMinimumRedistributionCost(int[] products) {
  // write your code here
}
Checking account…