Source: AMAZON INTERVIEW QUESTION
Given a point P and other N points in two dimensional space, find K points
What is wrong with below approach ?
1) Calculate distance from given point to other points.
2) Store the distance and index of that point to TreeMap
3) Select top K elements from map. It's values will give index of Point element from points array.
The map is sorted according to the natural ordering of its keys, or by a Comparator provided at map creation time,