6 kyu

Closest pair of points

Description:

Given a number of points on a plane, your task is to find two points with the smallest distance between them.

Each points will be represented as an array with 2 coordinates.

Example

  1  2  3  4  5  6  7  8  9
1  
2    . A
3                . D
4                   . F       
5             . C
6              
7                . E
8    . B
9                   . G

For the plane above, the input will be:

[
  [2,2], // A
  [2,8], // B
  [5,5], // C
  [6,3], // D
  [6,7], // E
  [7,4], // F
  [7,8]  // G
]

The two points that are closest to each other are D and F. Expected answer should be an array with both points in any order. [[6,3],[7,4]] or [[7,4],[6,3]] are valid answers for the example above.

More information on http://en.wikipedia.org/wiki/Closest_pair_of_points_problem

Algorithms

Stats:

CreatedMay 16, 2014
PublishedMay 16, 2014
Warriors Trained787
Total Skips59
Total Code Submissions2594
Total Times Completed357
JavaScript Completions357
Total Stars24
% of votes with a positive feedback rating91% of 116
Total "Very Satisfied" Votes97
Total "Somewhat Satisfied" Votes16
Total "Not Satisfied" Votes3
Total Rank Assessments21
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • kirjs Avatar
  • smile67 Avatar
Ad