Find Minimum Cost
Amazon's warehouse management team is planning to roll out certain standards and checks that every Amazon Warehouse Manager will follow. Some products may need to be moved initially from one warehouse to another so that each warehouse complies.
A warehouse stores n identical containers arranged in the form of a circle. The distance between two adjacent containers is 1. Each container in a warehouse should hold the same number of products. Plan the optimal set of movements under the following rules.
- Move products from any location in either the clockwise or the anti-clockwise direction. The direction must remain the same throughout the remaining moves.
- While moving, collect excess products from some locations and deliver them to other locations that need more units.
- The cost of each product transfer is the distance the product is moved.
- The total cost is the sum of the costs for all products transferred.
Find the minimum cost such that finally, every container has the same number of products.
Note: In the examples, positions are one-indexed. It is guaranteed that it is always possible to distribute the products equally.
** Say TYVM to spike for the 1000 times! **
Constraints: ``
Example
Unlock to view complete problem details
and practice with sample input/output
View Test Cases & Run Code requires membership
