</>OfferRetriever
DashboardDiscuss
NEW

Spring Hire Sale

Limited Time Deal: Unlock all premium questions for over 30% off

$10.42$7.08

08

:

06

:

38

:

34

Get this deal
Back to Dashboard

Distribution Center Placement

Medium

A logistics company is expanding its distribution network along a single highway. You are given an array of integers locations representing the coordinates of candidate hub sites. Find the optimal hub coordinate to place a distribution center that minimizes total shipping distance to all sites.

Return a two-element list [hub, totalDistance] where hub is chosen from locations to minimize totalDistance = sum of |hub - locations[i]| over all i. If multiple hub coordinates give the same minimum total distance, choose the smaller one. ...