Minimum Warehouse Connection Cost

Asked at Amazon · Coding Questions · Difficulty: Medium

Warehouses have non-decreasing `warehouseCapacity` (1-indexed); a hub sits at the last position `n`. A warehouse at position `i` connects to the nearest hub at a position `>= i`, costing `capacity[hub] - capacity[i]`. For each query `[hubA, hubB]` (two extra hubs), return the total connection cost when every warehouse uses its nearest available hub (`hubA`, `hubB`, or `n`).

Loading the problem…