Coding: K Shuttle Pickup Locations (L1)
You are given the coordinates of N people on a 2D grid. You want to open K shuttle pickup locations (pickup points) so that the sum of Manhattan (L1) distances from each person to their nearest pickup location is minimized.
Input
-
An integer
N
(number of people).
-
An array
points
of length
N
, where
points[i] = (xi, yi)
are integer coordinates.
-
An integer
K
(number of pickup locations).
Output
-
Return the
minimum possible total L1 distance
:
∑i=1Nminj=1..K(∣xi−Xj∣+∣yi−Yj∣)
where (Xj,Yj) are the chosen pickup locations.
Clarifications / assumptions (state in your solution)
-
Are pickup locations required to be at integer coordinates?
-
Are pickup locations required to be chosen from existing people’s coordinates, or can they be anywhere?
Constraints (you may assume)
Provide an algorithm appropriate for interview constraints (e.g., N up to a few thousand, K up to N).