You are given a collection of points on a 2D plane, represented as an array points where each element is a pair [, ]. Your objective is to determine the smallest Euclidean distance that exists between any two different points in the set.
The Euclidean distance separating two points [, ] and [, ] is defined as .
You must devise an algorithm whose time complexity is no worse than O(N log N).
Constraints:
2 ≤ points.length ≤ 10⁴points[i].length = 2Example 1:
points = [[0, 0], [1, 1], [2, 2]]
1.414214
The pairwise distances are: between [0, 0] and [1, 1] = \sqrt{2} ≈ 1.414214, between [0, 0] and [2, 2] = \sqrt{8} ≈ 2.828427, and between [1, 1] and [2, 2] = \sqrt{2} ≈ 1.414214. The smallest among them is 1.414214.
Example 2:
points = [[0, 0], [3, 4]]
5.000000
Example 3:
points = [[1, 1], [1, 2], [2, 1], [2, 2], [3, 3], [4, 4]]
1.000000
Example 1
Input:
3
0 0
1 1
2 2
Output: 1.414214
Example 2
Input:
2
0 0
3 4
Output: 5.000000