Get Minimum Connection Cost

Problem Overview

  • Compute the minimum total connection cost for n warehouses with non-decreasing capacities, where each connects to the nearest hub at or beyond its index (two added hubs hubA<hubB<n plus central hub at n); cost = capacity[j] - capacity[i].
  • Input: warehouseCapacity (1-based, non-decreasing) and q queries (hubA, hubB), each independent. Output: one long integer per query.
  • Context: models routing and overhead optimization in Amazon’s logistics network.
  • From Amazon interviews; a coding interview interview question problem.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: