Comment by ojr
2 days ago
it wasn't just euclidean distance of course, it was this leetcode problem k closest points to origin https://leetcode.com/problems/k-closest-points-to-origin/des..., I thought if I needed a heap I would have to implement it myself didn't know I can use a library
I.e. the nearest neighbor problem. Presumably seeing if the candidate gave a naive solution and was able to optimize or find a more ideal solution
its not a nearest neighbor problem that is incorrect, they expect candidates to have the heap solution on the first go, you have 10-15 minutes to answer, no time to optimize, cheaters get blacklisted, welcome to the new reality
Finding the k points closest to the origin (or any other point) is obviously the k-nearest neighbors problem. What algorithm and data structure you use does not change that.
https://en.wikipedia.org/wiki/Nearest_neighbor_search
edit: If you want to use a heap, the general solution is to define an appropriate cost function; e.g., the p-norm distance to a reference point. Use a union type with the distance (for the heap's comparisons) and the point itself.
1 reply →
Wish it was more how you think than requiring boolean correct/incorrect answer on the whiteboard after 15min.