Minimize Warehouse Transfer Cost
Learn this problemProblem statement
Note π - Initially, I thought this problem might be a duplicate of an existing one, but I wasn't able to find it. If you happen to come across it as a duplicate, please let us know! Thank you so much in advance!! You are the best!! πΏοΈ
Updated on 06-23-2026 :D This problem has been confirmed as a duplicate version of Find Minimum Cost. Huge thanks to the friend in the solution section who helped identify the duplicate π§‘οΌ I'd recommend practicing the linked version as it is more complete.
Basically, Amazon has its warehouses lined up in a circle, you can start from any warehouse move in either clockwise or anti-clockwise direction, the direction must remain the same throughout the remaining moves.
Each warehouse stores some items. The goal is to collect excess items from some warehouses and deliver them to others need them, so that each warehouse stores the same number of items in the end (guaranteed).
The distance between 2 adjacent warehouses is 1, and the cost of each product transfer is the distance the product is moved.
Function
minimizeWarehouseTransferCost(warehouses: int[]) β long
Complete the function minimizeWarehouseTransferCost in the editor.
minimizeWarehouseTransferCost has the following parameter:
int[] warehouses: an array of integers representing the number of items in each warehouse
Returns
long integer: the minimum cost to make all warehouses store the same number of items
Examples
Example 1
warehouses = [6, 6, 6, 3, 4]return = 7The source compares two possible routes with costs 7 and 8. Since the problem asks for the minimum cost, the example output is 7.
More Amazon problems
- Secure Maximum DeliveriesOA Β· Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW Β· Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN Β· Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN Β· Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW Β· Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW Β· Seen Jul 2026
- Maximum System Memory CapacityOA Β· Seen Jul 2026
- Package Delivery SystemOA Β· Seen Jul 2026