Back to problems

Minimum Sum-of-Distances Meeting Point on a Line

Algorithm · LinkedIn · Medium

Requirements For an integer array points, choose and return a coordinate x that makes sum( p - x ) over every p in points as small as possible. The target answer is the median of points. It can be found in O(N) time with quickselect (such as std::nth_element or numpy.partition), while sorting provides an O(N log N) alternative. This interview round evaluates three main areas: Recognize promptly that the median is required, rather than pursuing an inappropriate O(N log N)…

Checking your access…