FastPrepMinimum Circular Redistribution Cost
Problem · Array

Minimum Circular Redistribution Cost

HardAmazon logoAmazonNEW GRADFULLTIMEOA
See Amazon hiring insights

Problem statement

A warehouse has n identical containers arranged in a circle. Adjacent containers are one unit apart, and the goal is to make every container hold the same number of products.

The problem statement continues
Pro

Examples

Example 1

products = [3, 4, 6, 6, 6]return = 7

Consider a circular arrangement of containers. The units in each container are products = [3, 4, 6, 6, 6].

Position 1 Position 2 Position 3 Position 4 Position 5 3 Products 4 Products 6 Products 6 Products 6 Products

Option 1:

Start at the 3rd position and move clockwise. Collect one product each from the 3rd, 4th, and 5th positions.

Transfer the products from:

  • the 5th position to the 1st position, the cost is 1.
  • the 4th position to the 1st position, the cost is 2.
  • the 3rd position to the 2nd position, the cost is 4.

Now each container has 5 units and the total cost is 1 + 2 + 4 = 7.

Option 2:

Start at the 5th position moving anti-clockwise. Collect one product each from the 5th, 4th, and 3rd positions.

Transfer the product from:

  • the 3rd position to the 1st position, the cost is 2.
  • the 4th position to the 1st position, the cost is 3.
  • the 5th position to the 2nd position, the cost is 3.

Now each container has 5 units and the total cost is 2 + 3 + 3 = 8. Return 7, the minimum cost achievable.

3 original screenshots from the interview report
Pro
FastPrep Pro
Reported in 1 Amazon interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 1 more worked example, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week
CodePython 3
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Amazon interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 1 more worked example, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week