A store-locator map shows markers at whole-number coordinates in points, each [x, y]. Markers that are too close overlap, so the map needs the distance between the two closest markers.
Write closestPairDistance(points) that returns the smallest squared distance (x1 - x2)² + (y1 - y2)² between any two different markers in the list. Two markers may sit at the same coordinates, which gives 0.
A simple check of every pair is O(n²). Aim for O(n log n).
Input: points = [[0,0],[3,4],[1,1]] Output: 2
[0, 0] and [1, 1] are 1² + 1² = 2 apart, closer than any other pair.
Input: points = [[5,5],[5,5]] Output: 0
Two markers at the same spot are 0 apart.
2 <= points.length <= 10^5-10^6 <= x, y <= 10^6Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #315 Closest Pair of Map Markers. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.