Draft

Find N smallest points in 2-D plane.

Description:

You are given a vector of points in the 2 dimensional plane (x,y) and a number "n" (n will always be smaller than the number of points in the vector).

Your task is to return the n points in the vector with the smallest L^2 norm (http://mathworld.wolfram.com/L2-Norm.html), from smallest to largest.

A point in the 2-D plane will be represented as a pair<int,int> in C++.

Example:

Input: n = 2, points = {{1,1},{3,2},{2,2},{3,4}}

norm({1,1}) = sqrt(1^2+1^2) = 1.4142135623730951

norm({3,2}) = sqrt(3^2+2^2) = 3.605551275463989

norm({2,2}) = sqrt(2^2+2^2) = 2.8284271247461903

norm({3,4}) = sqrt(1^2+1^2) = 5

Therefore the expected output is: {{1,1},{2,2}}

Algorithms
Fundamentals
Mathematics

More By Author:

Check out these other kata created by SinisterMinister

Stats:

CreatedAug 14, 2017
Warriors Trained98
Total Skips15
Total Code Submissions122
Total Times Completed26
C++ Completions26
Total Stars0
% of votes with a positive feedback rating80% of 15
Total "Very Satisfied" Votes11
Total "Somewhat Satisfied" Votes2
Total "Not Satisfied" Votes2
Total Rank Assessments15
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • SinisterMinister Avatar
  • Voile Avatar
Ad