Ctrl K

Drop One Point

Hard
You are given a set of points points on a plane, where points[i] = [x, y] are integer coordinates. The distance between points is measured along the grid: between (x1, y1) and (x2, y2) it is |x1 − x2| + |y1 − y2|. The **span** of a set is the largest such distance between two of its points. Remove exactly one point so that the span of the rest is as small as possible, and return that span. Points may coincide.
Example 1
points=[[1, 1], [2, 5], [6, 2], [20, 20]] → 7

The point (20, 20) is far from the rest, so we drop it. Among the others the farthest pair is (2, 5) and (6, 2): |2 − 6| + |5 − 2| = 7.

Example 2
points=[[4, 4], [4, 4], [9, 1]] → 0

Dropping (9, 1) leaves two identical points, 0 apart.

Example 3
points=[[1, 1], [3, 3], [5, 5], [7, 7]] → 8
Constraints
  • 3 ≤ len(points) ≤ 10⁵
  • points[i] = [x, y], 1 ≤ x, y ≤ 10⁸
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsNearest Pair of Sensors HardBest View for a Turning Camera HardCorner Pairs With No One Between HardClean Rectangle on Pins HardSmallest Paddock Medium
loading Python…
Input
points=[[1, 1], [2, 5], [6, 2], [20, 20]]
Expected
7

Run checks the first 3 tests in your browser. Submit checks all 155 tests on the server, hidden ones included.