Get Minimum Total Distance

Problem Overview

  • Choose 2 warehouse locations on a line so the total distance from each distribution center to its nearest warehouse is minimized.
  • Input: array dist_centers (n up to 2000, positions 0 to 1e6); Output: minimum total distance as an integer.
  • Models Amazon logistics planning for placing warehouses to serve centers along a straight route.
  • From Amazon interviews, this coding interview interview question is a classic optimization 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: